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 61642d64b5
commit 874db26104
32 changed files with 300 additions and 147 deletions

View file

@ -146,15 +146,17 @@ impl HTMLCollection {
pub fn by_class_name(window: &JSRef<Window>, root: &JSRef<Node>, classes: DOMString)
-> Temporary<HTMLCollection> {
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)
}
@ -220,8 +222,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(&satom!("name")) == key ||
elem.get_string_attribute(&satom!("id")) == key })
.map(|maybe_elem| Temporary::from_rooted(&*maybe_elem)),
Live(ref root, ref filter) => {
let root = root.root();
@ -232,8 +234,8 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
.map(|elem| elem.clone())
})
.find(|elem| {
elem.get_string_attribute("name") == key ||
elem.get_string_attribute("id") == key })
elem.get_string_attribute(&satom!("name")) == key ||
elem.get_string_attribute(&satom!("id")) == key })
.map(|maybe_elem| Temporary::from_rooted(&maybe_elem))
}
}