1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

LibWeb: Make CSS rule cache smarter about pseudo elements

Instead of putting every rule that matches a pseudo element in the
same bucket, let them go in the best ID/class/tag name bucket instead.
Then, add a flag to MatchingRule that says whether it contains a
pseudo element in the rightmost compound selector.

When deciding which selectors to run for an element, we can now simply
filter in/out pseudo element selectors as appropriate depending on what
we're trying to match.

This fixes an issue where pages using Font Awesome had 1700+ rules in the
pseudo-element rule cache. (This meant all those rules had to run
against every element twice or more while instantiating pseudo elements.)
This commit is contained in:
Andreas Kling 2023-03-09 19:27:23 +01:00
parent 2a607e9ebc
commit 4bfdc4db17
2 changed files with 49 additions and 39 deletions

View file

@ -26,6 +26,7 @@ struct MatchingRule {
size_t rule_index { 0 };
size_t selector_index { 0 };
u32 specificity { 0 };
bool contains_pseudo_element { false };
};
class PropertyDependencyNode : public RefCounted<PropertyDependencyNode> {
@ -111,7 +112,6 @@ private:
HashMap<FlyString, Vector<MatchingRule>> rules_by_id;
HashMap<FlyString, Vector<MatchingRule>> rules_by_class;
HashMap<FlyString, Vector<MatchingRule>> rules_by_tag_name;
HashMap<Selector::PseudoElement, Vector<MatchingRule>> rules_by_pseudo_element;
Vector<MatchingRule> other_rules;
};