mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
style: Simplify a bit hot selector-matching loop
Note that element.clone() is just copying a couple pointers. Have a single place where we compute the next element and check for linky-ness. This saves a couple checks (very very minor win in the micro-benchmark I've been looking at, but consistent). Depends on D145484 Differential Revision: https://phabricator.services.mozilla.com/D145485
This commit is contained in:
parent
a21762fc5b
commit
2939bf1a12
1 changed files with 7 additions and 11 deletions
|
@ -490,19 +490,21 @@ where
|
||||||
Combinator::PseudoElement => SelectorMatchingResult::NotMatchedGlobally,
|
Combinator::PseudoElement => SelectorMatchingResult::NotMatchedGlobally,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut next_element =
|
|
||||||
next_element_for_combinator(element, combinator, &selector_iter, &context);
|
|
||||||
|
|
||||||
// Stop matching :visited as soon as we find a link, or a combinator for
|
// Stop matching :visited as soon as we find a link, or a combinator for
|
||||||
// something that isn't an ancestor.
|
// something that isn't an ancestor.
|
||||||
let mut visited_handling = if element.is_link() || combinator.is_sibling() {
|
let mut visited_handling = if combinator.is_sibling() {
|
||||||
VisitedHandlingMode::AllLinksUnvisited
|
VisitedHandlingMode::AllLinksUnvisited
|
||||||
} else {
|
} else {
|
||||||
context.visited_handling()
|
context.visited_handling()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut element = element.clone();
|
||||||
loop {
|
loop {
|
||||||
let element = match next_element {
|
if element.is_link() {
|
||||||
|
visited_handling = VisitedHandlingMode::AllLinksUnvisited;
|
||||||
|
}
|
||||||
|
|
||||||
|
element = match next_element_for_combinator(&element, combinator, &selector_iter, &context) {
|
||||||
None => return candidate_not_found,
|
None => return candidate_not_found,
|
||||||
Some(next_element) => next_element,
|
Some(next_element) => next_element,
|
||||||
};
|
};
|
||||||
|
@ -549,12 +551,6 @@ where
|
||||||
// matching on the next candidate element.
|
// matching on the next candidate element.
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if element.is_link() {
|
|
||||||
visited_handling = VisitedHandlingMode::AllLinksUnvisited;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_element = next_element_for_combinator(&element, combinator, &selector_iter, &context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue