1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +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

@ -27,6 +27,7 @@
#pragma once
#include <AK/Forward.h>
#include <LibWeb/DOM/AttributeNames.h>
#include <LibWeb/Forward.h>
#include <LibWeb/TreeNode.h>
@ -39,7 +40,7 @@ public:
{
const Element* found_element = nullptr;
static_cast<const NodeType*>(this)->template for_each_in_subtree_of_type<Element>([&](auto& element) {
if (element.attribute("id") == id) {
if (element.attribute(HTML::AttributeNames::id) == id) {
found_element = &element;
return IterationDecision::Break;
}
@ -53,7 +54,7 @@ public:
}
protected:
NonElementParentNode() {}
NonElementParentNode() { }
};
}