mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:58:13 +00:00
LibWeb: Cache the "id" attribute value on DOM::Element as FlyString
This will allow us to do O(1) checks against the element ID when matching selectors, etc.
This commit is contained in:
parent
6b580d68a3
commit
1c62ee9396
2 changed files with 10 additions and 1 deletions
|
@ -478,7 +478,12 @@ void Element::attribute_changed(FlyString const& name, Optional<DeprecatedString
|
|||
{
|
||||
auto value_or_empty = value.value_or("");
|
||||
|
||||
if (name == HTML::AttributeNames::class_) {
|
||||
if (name == HTML::AttributeNames::id) {
|
||||
if (!value.has_value())
|
||||
m_id = {};
|
||||
else
|
||||
m_id = MUST(FlyString::from_deprecated_fly_string(value_or_empty));
|
||||
} else if (name == HTML::AttributeNames::class_) {
|
||||
auto new_classes = value_or_empty.split_view(Infra::is_ascii_whitespace);
|
||||
m_classes.clear();
|
||||
m_classes.ensure_capacity(new_classes.size());
|
||||
|
|
|
@ -375,6 +375,8 @@ public:
|
|||
};
|
||||
Directionality directionality() const;
|
||||
|
||||
Optional<FlyString> const& id() const { return m_id; }
|
||||
|
||||
protected:
|
||||
Element(Document&, DOM::QualifiedName);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
@ -411,6 +413,8 @@ private:
|
|||
Vector<FlyString> m_classes;
|
||||
Optional<Dir> m_dir;
|
||||
|
||||
Optional<FlyString> m_id;
|
||||
|
||||
Array<JS::GCPtr<Layout::Node>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)> m_pseudo_element_nodes;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reaction-queue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue