From 2c8866e919f864e989eeacf73b515fbb4325111d Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 6 Jun 2017 17:04:03 -0500 Subject: [PATCH] Stop looking for relevant links once found Once we've encountered a relevant link, stop looking for potential relevant link. A relevant link is only the nearest ancestor link, so it is incorrect to keep looking once one is found. This only matters for the somewhat unusual case of nested links. MozReview-Commit-ID: LiXsUGWfxg3 --- components/selectors/matching.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index 84ddde2b261..0ab6c7e29e0 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -225,8 +225,10 @@ impl RelevantLinkStatus { -> RelevantLinkStatus where E: Element, { + // If a relevant link was previously found, we no longer want to look + // for links. Only the nearest ancestor link is considered relevant. if *self != RelevantLinkStatus::Looking { - return *self + return RelevantLinkStatus::NotLooking } if !element.is_link() { @@ -407,7 +409,7 @@ pub fn matches_complex_selector(complex_selector: &Selector, match matches_complex_selector_internal(iter, element, context, - RelevantLinkStatus::Looking, + &mut RelevantLinkStatus::Looking, flags_setter) { SelectorMatchingResult::Matched => true, _ => false @@ -417,13 +419,13 @@ pub fn matches_complex_selector(complex_selector: &Selector, fn matches_complex_selector_internal(mut selector_iter: SelectorIter, element: &E, context: &mut MatchingContext, - relevant_link: RelevantLinkStatus, + relevant_link: &mut RelevantLinkStatus, flags_setter: &mut F) -> SelectorMatchingResult where E: Element, F: FnMut(&E, ElementSelectorFlags), { - let mut relevant_link = relevant_link.examine_potential_link(element, context); + *relevant_link = relevant_link.examine_potential_link(element, context); let matches_all_simple_selectors = selector_iter.all(|simple| { matches_simple_selector(simple, element, context, &relevant_link, flags_setter) @@ -449,7 +451,7 @@ fn matches_complex_selector_internal(mut selector_iter: SelectorIter { // Only ancestor combinators are allowed while looking for // relevant links, so switch to not looking. - relevant_link = RelevantLinkStatus::NotLooking; + *relevant_link = RelevantLinkStatus::NotLooking; (element.prev_sibling_element(), SelectorMatchingResult::NotMatchedAndRestartFromClosestDescendant) }