Skip to content

Commit

Permalink
LibWeb: Add fast_is<T> for HTML::HTMLAnchorElement
Browse files Browse the repository at this point in the history
We were spending 20% of style computation time on the HTML spec on
deciding whether DOM nodes were HTML anchor (a) tags or not.
  • Loading branch information
awesomekling committed Mar 2, 2022
1 parent 65b38f2 commit ad9f3f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/DOM/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Node
virtual bool is_editable() const;

virtual bool is_html_html_element() const { return false; }
virtual bool is_html_anchor_element() const { return false; }
virtual bool is_html_template_element() const { return false; }
virtual bool is_browsing_context_container() const { return false; }

Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class HTMLAnchorElement final

virtual bool is_focusable() const override { return has_attribute(HTML::AttributeNames::href); }

virtual bool is_html_anchor_element() const override { return true; }

private:
// ^DOM::Element
virtual void parse_attribute(FlyString const& name, String const& value) override;
Expand All @@ -35,3 +37,8 @@ class HTMLAnchorElement final
};

}

namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLAnchorElement>() const { return is_html_anchor_element(); }
}

0 comments on commit ad9f3f7

Please sign in to comment.