script: Use atom comparison in more places, especially for attributes.

75% improvement in style recalc for Guardians of the Galaxy.
This commit is contained in:
Patrick Walton 2014-09-12 13:28:37 -07:00
parent d168501555
commit ee2ccc4f87
31 changed files with 305 additions and 237 deletions

View file

@ -17,7 +17,6 @@ use devtools_traits::AttrInfo;
use servo_util::str::{DOMString, split_html_space_chars};
use std::cell::{Ref, RefCell};
use std::mem;
use std::slice::Items;
use string_cache::{Atom, Namespace};
pub enum AttrSettingType {
@ -51,9 +50,9 @@ impl AttrValue {
AtomAttrValue(value)
}
pub fn tokens<'a>(&'a self) -> Option<Items<'a, Atom>> {
pub fn tokens<'a>(&'a self) -> Option<&'a [Atom]> {
match *self {
TokenListAttrValue(_, ref tokens) => Some(tokens.iter()),
TokenListAttrValue(_, ref tokens) => Some(tokens.as_slice()),
_ => None
}
}
@ -215,17 +214,19 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
pub trait AttrHelpersForLayout {
unsafe fn value_ref_forever(&self) -> &'static str;
unsafe fn value_atom_forever(&self) -> Option<Atom>;
unsafe fn value_tokens_forever(&self) -> Option<Items<Atom>>;
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
unsafe fn local_name_atom_forever(&self) -> Atom;
}
impl AttrHelpersForLayout for Attr {
#[inline]
unsafe fn value_ref_forever(&self) -> &'static str {
// cast to point to T in RefCell<T> directly
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value);
value.as_slice()
}
#[inline]
unsafe fn value_atom_forever(&self) -> Option<Atom> {
// cast to point to T in RefCell<T> directly
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value);
@ -235,15 +236,17 @@ impl AttrHelpersForLayout for Attr {
}
}
unsafe fn value_tokens_forever(&self) -> Option<Items<Atom>> {
#[inline]
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]> {
// cast to point to T in RefCell<T> directly
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value);
match *value {
TokenListAttrValue(_, ref tokens) => Some(tokens.iter()),
TokenListAttrValue(_, ref tokens) => Some(tokens.as_slice()),
_ => None,
}
}
#[inline]
unsafe fn local_name_atom_forever(&self) -> Atom {
self.local_name.clone()
}