浏览代码

LibWeb: Add fast_is<HTMLElement>()

This avoids slow RTTI lookups in selector matching.
Andreas Kling 3 年之前
父节点
当前提交
2ad98fdf80
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      Userland/Libraries/LibWeb/DOM/Node.h
  2. 7 0
      Userland/Libraries/LibWeb/HTML/HTMLElement.h

+ 1 - 0
Userland/Libraries/LibWeb/DOM/Node.h

@@ -87,6 +87,7 @@ public:
 
     virtual bool is_editable() const;
 
+    virtual bool is_html_element() const { return false; }
     virtual bool is_html_html_element() const { return false; }
     virtual bool is_html_anchor_element() const { return false; }
     virtual bool is_html_base_element() const { return false; }

+ 7 - 0
Userland/Libraries/LibWeb/HTML/HTMLElement.h

@@ -53,6 +53,8 @@ protected:
     virtual void parse_attribute(FlyString const& name, String const& value) override;
 
 private:
+    virtual bool is_html_element() const final { return true; }
+
     // ^HTML::GlobalEventHandlers
     virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; }
 
@@ -73,3 +75,8 @@ private:
 };
 
 }
+
+namespace Web::DOM {
+template<>
+inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
+}