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:
Andreas Kling 2022-09-15 13:51:30 +02:00
commit 1dd4e2dc87
Notes: sideshowbarker 2024-07-17 07:08:58 +09:00
4 changed files with 24 additions and 10 deletions

View file

@ -372,7 +372,7 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
builder.appendff("{}:", type_description);
// FIXME: This is goofy
if (simple_selector.value.has<FlyString>())
if (simple_selector.value.has<CSS::Selector::SimpleSelector::Name>())
builder.append(simple_selector.name());
if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoClass) {