LibWeb: Skip quick selector rejection using ancestor filter if possible

If selector does not have any descendant combinators then we know for
sure it won't be filtered out by ancestor filter, which means there is
no need to check for it.

This change makes hover style invalidation go faster on Discord where
with this change we spend 4-5% in `should_reject_with_ancestor_filter()`
instead of 20%.
This commit is contained in:
Aliaksandr Kalenik 2025-02-20 16:25:29 +01:00 committed by Alexander Kalenik
commit 1843a54df7
Notes: github-actions[bot] 2025-02-20 18:49:27 +00:00
4 changed files with 6 additions and 2 deletions

View file

@ -503,7 +503,8 @@ Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::Element c
if (!rule_is_relevant_for_current_scope)
return;
if (should_reject_with_ancestor_filter(rule_to_run.selector))
auto const& selector = rule_to_run.selector;
if (selector.can_use_ancestor_filter() && should_reject_with_ancestor_filter(selector))
return;
rules_to_run.unchecked_append(rule_to_run);