From 93de6edbc99204b3e3efc05ca4b6d137d8350f6c Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 18 Jan 2023 00:36:42 +0000 Subject: [PATCH] style: Apply slow selector flags before matching This patch fixes a bug introduced by bug 1808228/D166266, where, if an element does not initially match :nth-child(An+B of selector list) or :nth-last-child(An+B of selector list), changing a sibling or ancestor will not invalidate that element. Differential Revision: https://phabricator.services.mozilla.com/D166982 --- components/selectors/matching.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index e82a61f6fa6..a8f96daf086 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -894,18 +894,6 @@ where if element.ignores_nth_child_selectors() { return false; } - /* - * This condition could be bound as element_matches_selectors and used in - * nth_child_index() as element_matches_selectors && - * list_matches_complex_selector(selectors, &curr, context) - * , but since element_matches_selectors would need still need to be - * computed in that case in order to utilize the cache, there would be no - * performance benefit for building up nth-{,last-}child(.. of ..) caches - * where the element does not match the selector list. - */ - if !selectors.is_empty() && !list_matches_complex_selector(selectors, element, context) { - return false; - } let NthSelectorData { ty, a, b, .. } = *nth_data; let is_of_type = ty.is_of_type(); @@ -943,6 +931,10 @@ where }); } + if !selectors.is_empty() && !list_matches_complex_selector(selectors, element, context) { + return false; + } + // :first/last-child are rather trivial to match, don't bother with the // cache. if is_edge_child_selector {