mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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:
parent
61642d64b5
commit
874db26104
32 changed files with 300 additions and 147 deletions
|
@ -11,7 +11,6 @@ use url::Url;
|
|||
|
||||
use servo_util::atom::Atom;
|
||||
use servo_util::bloom::BloomFilter;
|
||||
use servo_util::namespace;
|
||||
use servo_util::smallvec::VecLike;
|
||||
use servo_util::sort;
|
||||
|
||||
|
@ -106,20 +105,14 @@ impl SelectorMap {
|
|||
None => {}
|
||||
}
|
||||
|
||||
match element.get_attr(&namespace::Null, "class") {
|
||||
Some(ref class_attr) => {
|
||||
// FIXME: Store classes pre-split as atoms to make the loop below faster.
|
||||
for class in class_attr.split(SELECTOR_WHITESPACE) {
|
||||
SelectorMap::get_matching_rules_from_hash(node,
|
||||
parent_bf,
|
||||
&self.class_hash,
|
||||
&Atom::from_slice(class),
|
||||
matching_rules_list,
|
||||
shareable);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
element.each_class(|class| {
|
||||
SelectorMap::get_matching_rules_from_hash(node,
|
||||
parent_bf,
|
||||
&self.class_hash,
|
||||
class,
|
||||
matching_rules_list,
|
||||
shareable);
|
||||
});
|
||||
|
||||
let local_name_hash = if node.is_html_element_in_html_document() {
|
||||
&self.lower_local_name_hash
|
||||
|
@ -467,7 +460,12 @@ impl DeclarationBlock {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn matches<E:TElement, N:TNode<E>>(selector_list: &SelectorList, element: &N, parent_bf: &Option<BloomFilter>) -> bool {
|
||||
pub fn matches<E:TElement,
|
||||
N:TNode<E>>(
|
||||
selector_list: &SelectorList,
|
||||
element: &N,
|
||||
parent_bf: &Option<BloomFilter>)
|
||||
-> bool {
|
||||
get_selector_list_selectors(selector_list).iter().any(|selector|
|
||||
selector.pseudo_element.is_none() &&
|
||||
matches_compound_selector(&*selector.compound_selectors, element, parent_bf, &mut false))
|
||||
|
@ -544,11 +542,13 @@ enum SelectorMatchingResult {
|
|||
/// Quickly figures out whether or not the compound selector is worth doing more
|
||||
/// work on. If the simple selectors don't match, or there's a child selector
|
||||
/// that does not appear in the bloom parent bloom filter, we can exit early.
|
||||
fn can_fast_reject<E: TElement, N: TNode<E>>(
|
||||
mut selector: &CompoundSelector,
|
||||
element: &N,
|
||||
parent_bf: &Option<BloomFilter>,
|
||||
shareable: &mut bool) -> Option<SelectorMatchingResult> {
|
||||
fn can_fast_reject<E:TElement,
|
||||
N:TNode<E>>(
|
||||
mut selector: &CompoundSelector,
|
||||
element: &N,
|
||||
parent_bf: &Option<BloomFilter>,
|
||||
shareable: &mut bool)
|
||||
-> Option<SelectorMatchingResult> {
|
||||
if !selector.simple_selectors.iter().all(|simple_selector| {
|
||||
matches_simple_selector(simple_selector, element, shareable) }) {
|
||||
return Some(NotMatchedAndRestartFromClosestLaterSibling);
|
||||
|
@ -681,11 +681,11 @@ fn matches_compound_selector_internal<E:TElement,
|
|||
/// `main/css/matching.rs`.)
|
||||
#[inline]
|
||||
pub fn matches_simple_selector<E:TElement,
|
||||
N:TNode<E>>(
|
||||
selector: &SimpleSelector,
|
||||
element: &N,
|
||||
shareable: &mut bool)
|
||||
-> bool {
|
||||
N:TNode<E>>(
|
||||
selector: &SimpleSelector,
|
||||
element: &N,
|
||||
shareable: &mut bool)
|
||||
-> bool {
|
||||
match *selector {
|
||||
LocalNameSelector(LocalNameSelector { ref name, ref lower_name }) => {
|
||||
let name = if element.is_html_element_in_html_document() { lower_name } else { name };
|
||||
|
@ -710,7 +710,7 @@ pub fn matches_simple_selector<E:TElement,
|
|||
// TODO: cache and intern class names on elements.
|
||||
ClassSelector(ref class) => {
|
||||
let element = element.as_element();
|
||||
element.has_class(class.as_slice())
|
||||
element.has_class(class)
|
||||
}
|
||||
|
||||
AttrExists(ref attr) => {
|
||||
|
@ -854,6 +854,7 @@ pub fn matches_simple_selector<E:TElement,
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn url_is_visited(_url: &str) -> bool {
|
||||
// FIXME: implement this.
|
||||
// This function will probably need to take a "session"
|
||||
|
@ -862,8 +863,7 @@ fn url_is_visited(_url: &str) -> bool {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn matches_generic_nth_child<'a,
|
||||
E:TElement,
|
||||
fn matches_generic_nth_child<E:TElement,
|
||||
N:TNode<E>>(
|
||||
element: &N,
|
||||
a: i32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue