From d0d7e5a782aa54fc3f6e6b6cd162d78fe9475283 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 2 Nov 2023 14:58:18 +0100 Subject: [PATCH] LibWeb: Use Element::id() in getElementById() This avoids the O(n) walk of element attributes, although there is still a huge space for improvement here if we start keeping a lookup cache for elements-by-ID. --- Userland/Libraries/LibWeb/DOM/NonElementParentNode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h index d0e3792bbda..f58e6dfc579 100644 --- a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h +++ b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h @@ -22,7 +22,7 @@ public: { JS::GCPtr found_element; static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { - if (element.attribute(HTML::AttributeNames::id) == id) { + if (element.id() == id) { found_element = &element; return IterationDecision::Break; } @@ -35,7 +35,7 @@ public: { JS::GCPtr found_element; static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { - if (element.attribute(HTML::AttributeNames::id) == id) { + if (element.id() == id) { found_element = &element; return IterationDecision::Break; }