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

@ -15,7 +15,6 @@ use script::dom::node::{TextNodeTypeId};
use servo_util::bloom::BloomFilter;
use servo_util::cache::{Cache, LRUCache, SimpleHashCache};
use servo_util::smallvec::{SmallVec, SmallVec16};
use servo_util::str::DOMString;
use std::mem;
use std::hash::{Hash, sip};
use std::slice::Items;
@ -165,7 +164,8 @@ pub struct StyleSharingCandidate {
pub style: Arc<ComputedValues>,
pub parent_style: Arc<ComputedValues>,
pub local_name: Atom,
pub class: Option<DOMString>,
// FIXME(pcwalton): Should be a list of atoms instead.
pub class: Option<String>,
}
impl PartialEq for StyleSharingCandidate {
@ -222,7 +222,7 @@ impl StyleSharingCandidate {
style: style,
parent_style: parent_style,
local_name: element.get_local_name().clone(),
class: element.get_attr(&ns!(""), "class")
class: element.get_attr(&ns!(""), &atom!("class"))
.map(|string| string.to_string()),
})
}
@ -231,10 +231,12 @@ impl StyleSharingCandidate {
if *element.get_local_name() != self.local_name {
return false
}
match (&self.class, element.get_attr(&ns!(""), "class")) {
// FIXME(pcwalton): Use `each_class` here instead of slow string comparison.
match (&self.class, element.get_attr(&ns!(""), &atom!("class"))) {
(&None, Some(_)) | (&Some(_), None) => return false,
(&Some(ref this_class), Some(element_class))
if element_class != this_class.as_slice() => {
(&Some(ref this_class), Some(element_class)) if
element_class != this_class.as_slice() => {
return false
}
(&Some(_), Some(_)) | (&None, None) => {}
@ -457,7 +459,8 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}
let ok = {
let element = self.as_element();
element.style_attribute().is_none() && element.get_attr(&ns!(""), "id").is_none()
element.style_attribute().is_none() &&
element.get_attr(&ns!(""), &atom!("id")).is_none()
};
if !ok {
return CannotShare(false)