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.
This commit is contained in:
Andreas Kling 2023-11-02 14:58:18 +01:00
parent e205f93cbb
commit d0d7e5a782
Notes: sideshowbarker 2024-07-18 01:43:16 +09:00

View file

@ -22,7 +22,7 @@ public:
{
JS::GCPtr<Element const> found_element;
static_cast<NodeType const*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](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<Element> found_element;
static_cast<NodeType*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
if (element.attribute(HTML::AttributeNames::id) == id) {
if (element.id() == id) {
found_element = &element;
return IterationDecision::Break;
}