Przeglądaj źródła

LibWeb: Streamline Node::enclosing_link_element() somewhat

No need to verify_cast repeatedly once we've confirmed the type.
Andreas Kling 3 lat temu
rodzic
commit
9888e29c14
1 zmienionych plików z 5 dodań i 2 usunięć
  1. 5 2
      Userland/Libraries/LibWeb/DOM/Node.cpp

+ 5 - 2
Userland/Libraries/LibWeb/DOM/Node.cpp

@@ -81,8 +81,11 @@ Node::~Node()
 const HTML::HTMLAnchorElement* Node::enclosing_link_element() const
 {
     for (auto* node = this; node; node = node->parent()) {
-        if (is<HTML::HTMLAnchorElement>(*node) && verify_cast<HTML::HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href))
-            return verify_cast<HTML::HTMLAnchorElement>(node);
+        if (!is<HTML::HTMLAnchorElement>(*node))
+            continue;
+        auto const& anchor_element = static_cast<HTML::HTMLAnchorElement const&>(*node);
+        if (anchor_element.has_attribute(HTML::AttributeNames::href))
+            return &anchor_element;
     }
     return nullptr;
 }