1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 07:45:07 +00:00

LibWeb: Add cached global attribute name FlyStrings

Instead of creating extremely common FlyStrings like "id" and "class"
on demand every time they are needed, we now have AttributeNames.h,
which provides Web::HTML::AttributeNames::{id,class_}

This avoids a bunch of string allocations during selector matching.
This commit is contained in:
Andreas Kling 2020-05-26 23:27:22 +02:00
parent 5069d380a8
commit 82444048de
7 changed files with 102 additions and 5 deletions

View file

@ -25,6 +25,7 @@
*/
#include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/DOM/AttributeNames.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Text.h>
@ -98,7 +99,7 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
case Selector::SimpleSelector::Type::Universal:
return true;
case Selector::SimpleSelector::Type::Id:
return component.value == element.attribute("id");
return component.value == element.attribute(HTML::AttributeNames::id);
case Selector::SimpleSelector::Type::Class:
return element.has_class(component.value);
case Selector::SimpleSelector::Type::TagName: