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
This commit is contained in:
Zach Hoffman 2023-01-18 00:36:42 +00:00 committed by Martin Robinson
parent 27f79b1d51
commit 93de6edbc9

View file

@ -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 {