Prechádzať zdrojové kódy

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.
Andreas Kling 1 rok pred
rodič
commit
d0d7e5a782

+ 2 - 2
Userland/Libraries/LibWeb/DOM/NonElementParentNode.h

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