From 6b191ab73d04586be00d99b7bee7d9c524ec146b Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 13 Jul 2023 19:54:03 +0200 Subject: [PATCH] LibJS+LibWeb: Add fast_is for JS::Object Solves problem that is() is quite hot in profiles while loading https://www.postgresql.org/about/featurematrix/. --- Userland/Libraries/LibJS/Runtime/Object.h | 1 + Userland/Libraries/LibWeb/DOM/Node.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 0566d44b4f..31bea5e02a 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -169,6 +169,7 @@ public: void define_native_function(Realm&, PropertyKey const&, SafeFunction(VM&)>, i32 length, PropertyAttributes attributes); void define_native_accessor(Realm&, PropertyKey const&, SafeFunction(VM&)> getter, SafeFunction(VM&)> setter, PropertyAttributes attributes); + virtual bool is_dom_node() const { return false; } virtual bool is_function() const { return false; } virtual bool is_typed_array() const { return false; } virtual bool is_string_object() const { return false; } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 5a3d62f099..b3e319ce04 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -84,6 +84,7 @@ public: virtual bool is_editable() const; + virtual bool is_dom_node() const final { return true; } 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; } @@ -704,3 +705,6 @@ private: }; } + +template<> +inline bool JS::Object::fast_is() const { return is_dom_node(); }