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

@ -21,12 +21,11 @@ use string_cache::Atom;
pub struct DOMTokenList {
reflector_: Reflector,
element: JS<Element>,
local_name: &'static str,
local_name: Atom,
}
impl DOMTokenList {
fn new_inherited(element: JSRef<Element>,
local_name: &'static str) -> DOMTokenList {
pub fn new_inherited(element: JSRef<Element>, local_name: Atom) -> DOMTokenList {
DOMTokenList {
reflector_: Reflector::new(),
element: JS::from_rooted(element),
@ -34,11 +33,11 @@ impl DOMTokenList {
}
}
pub fn new(element: JSRef<Element>,
local_name: &'static str) -> Temporary<DOMTokenList> {
pub fn new(element: JSRef<Element>, local_name: &Atom) -> Temporary<DOMTokenList> {
let window = window_from_node(element).root();
reflect_dom_object(box DOMTokenList::new_inherited(element, local_name),
&Window(*window), DOMTokenListBinding::Wrap)
reflect_dom_object(box DOMTokenList::new_inherited(element, local_name.clone()),
&Window(*window),
DOMTokenListBinding::Wrap)
}
}
@ -56,7 +55,7 @@ trait PrivateDOMTokenListHelpers {
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
fn attribute(self) -> Option<Temporary<Attr>> {
let element = self.element.root();
element.get_attribute(ns!(""), self.local_name)
element.get_attribute(ns!(""), &self.local_name)
}
fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<&'a str> {
@ -79,8 +78,8 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
// http://dom.spec.whatwg.org/#dom-domtokenlist-item
fn Item(self, index: u32) -> Option<DOMString> {
self.attribute().root().and_then(|attr| attr.value().tokens().and_then(|mut tokens| {
tokens.idx(index as uint).map(|token| token.as_slice().to_string())
self.attribute().root().and_then(|attr| attr.value().tokens().and_then(|tokens| {
tokens.get(index as uint).map(|token| token.as_slice().to_string())
}))
}
@ -93,9 +92,9 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains
fn Contains(self, token: DOMString) -> Fallible<bool> {
self.check_token_exceptions(token.as_slice()).map(|slice| {
self.attribute().root().and_then(|attr| attr.value().tokens().map(|mut tokens| {
self.attribute().root().and_then(|attr| attr.value().tokens().map(|tokens| {
let atom = Atom::from_slice(slice);
tokens.any(|token| *token == atom)
tokens.iter().any(|token| *token == atom)
})).unwrap_or(false)
})
}