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

@ -139,15 +139,17 @@ impl HTMLCollection {
-> Temporary<HTMLCollection> {
#[jstraceable]
struct ClassNameFilter {
classes: Vec<DOMString>
classes: Vec<Atom>
}
impl CollectionFilter for ClassNameFilter {
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
self.classes.iter().all(|class| elem.has_class(class.as_slice()))
self.classes.iter().all(|class| elem.has_class(class))
}
}
let filter = ClassNameFilter {
classes: split_html_space_chars(classes.as_slice()).map(|class| class.to_string()).collect()
classes: split_html_space_chars(classes.as_slice()).map(|class| {
Atom::from_slice(class)
}).collect()
};
HTMLCollection::create(window, root, box filter)
}
@ -216,8 +218,8 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
Static(ref elems) => elems.iter()
.map(|elem| elem.root())
.find(|elem| {
elem.get_string_attribute("name") == key ||
elem.get_string_attribute("id") == key })
elem.get_string_attribute(&atom!("name")) == key ||
elem.get_string_attribute(&atom!("id")) == key })
.map(|maybe_elem| Temporary::from_rooted(*maybe_elem)),
Live(ref root, ref filter) => {
let root = root.root();
@ -230,8 +232,8 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
}
})
.find(|elem| {
elem.get_string_attribute("name") == key ||
elem.get_string_attribute("id") == key })
elem.get_string_attribute(&atom!("name")) == key ||
elem.get_string_attribute(&atom!("id")) == key })
.map(|maybe_elem| Temporary::from_rooted(maybe_elem))
}
}