1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09: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:
Andreas Kling 2022-09-15 13:51:30 +02:00
parent d9c64ee876
commit 1dd4e2dc87
Notes: sideshowbarker 2024-07-17 07:08:58 +09:00
4 changed files with 24 additions and 10 deletions

View file

@ -353,9 +353,9 @@ static inline bool matches(CSS::Selector::SimpleSelector const& component, DOM::
return element.has_class(component.name());
case CSS::Selector::SimpleSelector::Type::TagName:
// See https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
if (is<HTML::HTMLElement>(element) && element.document().document_type() != DOM::Document::Type::XML)
return component.name().equals_ignoring_case(element.local_name());
return component.name() == element.local_name();
if (element.document().document_type() == DOM::Document::Type::HTML)
return component.lowercase_name() == element.local_name();
return component.name().equals_ignoring_case(element.local_name());
case CSS::Selector::SimpleSelector::Type::Attribute:
return matches_attribute(component.attribute(), element);
case CSS::Selector::SimpleSelector::Type::PseudoClass: