diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-13 18:59:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-13 19:11:29 +0200 |
commit | 5eef07d232fc179f0640bbb8cff575cd239c4d65 (patch) | |
tree | f2793ff33530445dcf110b42d0013636ee52c11c /Userland/Libraries/LibJS/Runtime/GlobalObject.h | |
parent | 53a8a11973cb4be1dc688fc245775540630bf87d (diff) | |
download | serenity-5eef07d232fc179f0640bbb8cff575cd239c4d65.zip |
LibJS: Avoid lots of string-to-int during global object construction
We were doing a *lot* of string-to-int conversion while creating a new
global object. This happened because Object::put() would try to convert
the property name (string) to an integer to see if it refers to an
indexed property.
Sidestep this issue by using PropertyName for the CommonPropertyNames
struct on VM (vm.names.foo), and giving PropertyName a flag that tells
us whether it's a string that *may be* a number.
All CommonPropertyNames are set up so they are known to not be numbers.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/GlobalObject.h')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index 910f3f17b1..16c766fdca 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -52,9 +52,9 @@ protected: virtual void visit_edges(Visitor&) override; template<typename ConstructorType> - void initialize_constructor(const FlyString& property_name, ConstructorType*&, Object* prototype); + void initialize_constructor(PropertyName const&, ConstructorType*&, Object* prototype); template<typename ConstructorType> - void add_constructor(const FlyString& property_name, ConstructorType*&, Object* prototype); + void add_constructor(PropertyName const&, ConstructorType*&, Object* prototype); private: virtual bool is_global_object() const final { return true; } @@ -94,11 +94,11 @@ private: }; template<typename ConstructorType> -inline void GlobalObject::initialize_constructor(const FlyString& property_name, ConstructorType*& constructor, Object* prototype) +inline void GlobalObject::initialize_constructor(PropertyName const& property_name, ConstructorType*& constructor, Object* prototype) { auto& vm = this->vm(); constructor = heap().allocate<ConstructorType>(*this, *this); - constructor->define_property(vm.names.name, js_string(heap(), property_name), Attribute::Configurable); + constructor->define_property(vm.names.name, js_string(heap(), property_name.as_string()), Attribute::Configurable); if (vm.exception()) return; if (prototype) { @@ -109,7 +109,7 @@ inline void GlobalObject::initialize_constructor(const FlyString& property_name, } template<typename ConstructorType> -inline void GlobalObject::add_constructor(const FlyString& property_name, ConstructorType*& constructor, Object* prototype) +inline void GlobalObject::add_constructor(PropertyName const& property_name, ConstructorType*& constructor, Object* prototype) { // Some constructors are pre-initialized separately. if (!constructor) |