From ff63b2603ddc58735286e03cca3d6ffa546561d8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Dec 2023 21:01:00 +0100 Subject: [PATCH] LibWeb: Use cached Element `id` attribute in HTMLCollection --- Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index ed18a597e2..13a8db2800 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -89,7 +89,7 @@ Element* HTMLCollection::named_item(FlyString const& name_) const auto elements = collect_matching_elements(); // 2. Return the first element in the collection for which at least one of the following is true: // - it has an ID which is key; - if (auto it = elements.find_if([&](auto& entry) { return entry->deprecated_attribute(HTML::AttributeNames::id) == name; }); it != elements.end()) + if (auto it = elements.find_if([&](auto& entry) { return entry->id().has_value() && entry->id().value() == name_; }); it != elements.end()) return *it; // - it is in the HTML namespace and has a name attribute whose value is key; if (auto it = elements.find_if([&](auto& entry) { return entry->namespace_uri() == Namespace::HTML && entry->name() == name; }); it != elements.end()) @@ -109,9 +109,9 @@ Vector HTMLCollection::supported_property_names() const for (auto& element : elements) { // 1. If element has an ID which is not in result, append element’s ID to result. - if (auto maybe_id = element->attribute(HTML::AttributeNames::id); maybe_id.has_value()) { - if (!result.contains_slow(maybe_id.value())) - result.append(maybe_id.release_value()); + if (auto const& id = element->id(); id.has_value()) { + if (!result.contains_slow(id.value())) + result.append(id.value()); } // 2. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append element’s name attribute value to result.