mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +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:
parent
5069d380a8
commit
82444048de
7 changed files with 102 additions and 5 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <LibJS/Runtime/PrimitiveString.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/Bindings/ElementWrapper.h>
|
||||
#include <LibWeb/DOM/AttributeNames.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
namespace Web {
|
||||
|
@ -131,7 +132,7 @@ void ElementWrapper::inner_html_setter(JS::Interpreter& interpreter, JS::Value v
|
|||
JS::Value ElementWrapper::id_getter(JS::Interpreter& interpreter)
|
||||
{
|
||||
if (auto* impl = impl_from(interpreter))
|
||||
return JS::js_string(interpreter, impl->attribute("id"));
|
||||
return JS::js_string(interpreter, impl->attribute(HTML::AttributeNames::id));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -141,7 +142,7 @@ void ElementWrapper::id_setter(JS::Interpreter& interpreter, JS::Value value)
|
|||
auto string = value.to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return;
|
||||
impl->set_attribute("id", string);
|
||||
impl->set_attribute(HTML::AttributeNames::id, string);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue