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:
Emilio Cobos Álvarez 2022-05-06 23:52:23 +00:00 committed by Martin Robinson
parent a21762fc5b
commit 2939bf1a12

View file

@ -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);
} }
} }