summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-19 11:28:44 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-19 23:12:47 +0100
commit0a911178cea4fcfb462eb7e256c51ed75756c7c8 (patch)
tree3a39005c6eeb9b9f21fc2b9d7fdb1b2c965a69a2 /Userland
parent43f0c92bcd7749fafe4b72206aed6b15fb14a4e4 (diff)
downloadserenity-0a911178cea4fcfb462eb7e256c51ed75756c7c8.zip
LibJS: Add fast_is<T> for StringObject and GlobalObject
Both of these are quite hot in profiles.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.h5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h5
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.h4
3 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
index 6261a23077..1062a3f75d 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
@@ -76,6 +76,8 @@ protected:
void add_constructor(const FlyString& property_name, ConstructorType*&, Object* prototype);
private:
+ virtual bool is_global_object() const final { return true; }
+
JS_DECLARE_NATIVE_FUNCTION(gc);
JS_DECLARE_NATIVE_FUNCTION(is_nan);
JS_DECLARE_NATIVE_FUNCTION(is_finite);
@@ -131,4 +133,7 @@ inline GlobalObject* Shape::global_object() const
return static_cast<GlobalObject*>(m_global_object);
}
+template<>
+inline bool Object::fast_is<GlobalObject>() const { return is_global_object(); }
+
}
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index 0e496fefb3..d80d67642d 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -112,6 +112,8 @@ public:
virtual bool is_array() 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; }
+ virtual bool is_global_object() const { return false; }
virtual const char* class_name() const override { return "Object"; }
virtual void visit_edges(Cell::Visitor&) override;
@@ -152,6 +154,9 @@ public:
void enable_transitions() { m_transitions_enabled = true; }
void disable_transitions() { m_transitions_enabled = false; }
+ template<typename T>
+ bool fast_is() const = delete;
+
protected:
enum class GlobalObjectTag { Tag };
enum class ConstructWithoutPrototypeTag { Tag };
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.h b/Userland/Libraries/LibJS/Runtime/StringObject.h
index 7fb32ebc63..7ba1b1ae4c 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.h
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.h
@@ -46,9 +46,13 @@ public:
}
private:
+ virtual bool is_string_object() const final { return true; }
virtual void visit_edges(Visitor&) override;
PrimitiveString& m_string;
};
+template<>
+inline bool Object::fast_is<StringObject>() const { return is_string_object(); }
+
}