mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:57:35 +00:00
LibWeb: Cache lowercased names in SimpleSelector
When matching selectors in HTML documents, we know that all the elements have lowercase local names already (the parser makes sure of this.) Style sheets still need to remember the original name strings, in case we want to match against non-HTML content like XML/SVG. To make the common HTML case faster, we now cache a lowercase version of the name with each type/class/id SimpleSelector. This makes tag type checks O(1) instead of O(n).
This commit is contained in:
parent
d9c64ee876
commit
1dd4e2dc87
4 changed files with 24 additions and 10 deletions
|
@ -142,8 +142,19 @@ public:
|
|||
CaseType case_type;
|
||||
};
|
||||
|
||||
struct Name {
|
||||
Name(FlyString n)
|
||||
: name(move(n))
|
||||
, lowercase_name(name.to_lowercase())
|
||||
{
|
||||
}
|
||||
|
||||
FlyString name;
|
||||
FlyString lowercase_name;
|
||||
};
|
||||
|
||||
Type type;
|
||||
Variant<Empty, Attribute, PseudoClass, PseudoElement, FlyString> value {};
|
||||
Variant<Empty, Attribute, PseudoClass, PseudoElement, Name> value {};
|
||||
|
||||
Attribute const& attribute() const { return value.get<Attribute>(); }
|
||||
Attribute& attribute() { return value.get<Attribute>(); }
|
||||
|
@ -151,8 +162,11 @@ public:
|
|||
PseudoClass& pseudo_class() { return value.get<PseudoClass>(); }
|
||||
PseudoElement const& pseudo_element() const { return value.get<PseudoElement>(); }
|
||||
PseudoElement& pseudo_element() { return value.get<PseudoElement>(); }
|
||||
FlyString const& name() const { return value.get<FlyString>(); }
|
||||
FlyString& name() { return value.get<FlyString>(); }
|
||||
|
||||
FlyString const& name() const { return value.get<Name>().name; }
|
||||
FlyString& name() { return value.get<Name>().name; }
|
||||
FlyString const& lowercase_name() const { return value.get<Name>().lowercase_name; }
|
||||
FlyString& lowercase_name() { return value.get<Name>().lowercase_name; }
|
||||
|
||||
String serialize() const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue