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

@ -13,13 +13,13 @@ use dom::element::{Element, AttributeHandlers};
use dom::node::Node;
use dom::window::Window;
use dom::virtualmethods::vtable_for;
use servo_util::atom::Atom;
use servo_util::namespace;
use servo_util::namespace::Namespace;
use servo_util::str::{DOMString, split_html_space_chars};
use std::cell::{Ref, RefCell};
use std::mem;
use std::slice::Items;
pub enum AttrSettingType {
FirstSetAttr,
@ -51,9 +51,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
}
}
@ -189,17 +189,19 @@ impl<'a> AttrHelpers 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.deref());
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.deref());
@ -209,15 +211,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.deref());
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()
}