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

LibWeb: Use cached Element id attribute in HTMLCollection

This commit is contained in:
Andreas Kling 2023-12-24 21:01:00 +01:00
parent 41f56b0df9
commit ff63b2603d

View file

@ -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<FlyString> HTMLCollection::supported_property_names() const
for (auto& element : elements) {
// 1. If element has an ID which is not in result, append elements 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 elements name attribute value to result.