mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user