mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +00:00
LibWeb: Cache attribute names in lowercase to speed up selector matching
When matching a CSS attribute selector against an HTML element, the attribute name is case-insensitive. Before this change, that meant we had to call equals_ignoring_ascii_case() on all the attribute names. We now cache the attribute name lowercased on each Attr node, which allows us to do FlyString-to-FlyString comparison (simple pointer comparison). This brings attribute selector matching from 6% to <1% when loading our GitHub repo at https://github.com/SerenityOS/serenity
This commit is contained in:
@@ -174,6 +174,19 @@ Attr const* NamedNodeMap::get_attribute(FlyString const& qualified_name, size_t*
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Attr const* NamedNodeMap::get_attribute_with_lowercase_qualified_name(FlyString const& lowercase_qualified_name) const
|
||||
{
|
||||
bool compare_as_lowercase = associated_element().namespace_uri() == Namespace::HTML;
|
||||
VERIFY(compare_as_lowercase);
|
||||
|
||||
for (auto const& attribute : m_attributes) {
|
||||
if (attribute->lowercase_name() == lowercase_qualified_name)
|
||||
return attribute;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace
|
||||
Attr* NamedNodeMap::get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name, size_t* item_index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user