mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS: Cache commonly used FlyStrings in the VM
Roughly 7% of test-js runtime was spent creating FlyStrings from string literals. This patch frontloads that work and caches all the commonly used names in LibJS on a CommonPropertyNames struct that hangs off VM.
This commit is contained in:
parent
9f6c5f68b6
commit
7b863330dc
45 changed files with 651 additions and 392 deletions
|
@ -31,15 +31,16 @@
|
|||
namespace JS {
|
||||
|
||||
ErrorConstructor::ErrorConstructor(GlobalObject& global_object)
|
||||
: NativeFunction("Error", *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Error, *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void ErrorConstructor::initialize(GlobalObject& global_object)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
NativeFunction::initialize(global_object);
|
||||
define_property("prototype", global_object.error_prototype(), 0);
|
||||
define_property("length", Value(1), Attribute::Configurable);
|
||||
define_property(vm.names.prototype, global_object.error_prototype(), 0);
|
||||
define_property(vm.names.length, Value(1), Attribute::Configurable);
|
||||
}
|
||||
|
||||
ErrorConstructor::~ErrorConstructor()
|
||||
|
@ -60,7 +61,7 @@ Value ErrorConstructor::construct(Function&)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
return Error::create(global_object(), "Error", message);
|
||||
return Error::create(global_object(), vm.names.Error, message);
|
||||
}
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
|
@ -70,9 +71,10 @@ Value ErrorConstructor::construct(Function&)
|
|||
} \
|
||||
void ConstructorName::initialize(GlobalObject& global_object) \
|
||||
{ \
|
||||
auto& vm = this->vm(); \
|
||||
NativeFunction::initialize(global_object); \
|
||||
define_property("prototype", global_object.snake_name##_prototype(), 0); \
|
||||
define_property("length", Value(1), Attribute::Configurable); \
|
||||
define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \
|
||||
define_property(vm.names.length, Value(1), Attribute::Configurable); \
|
||||
} \
|
||||
ConstructorName::~ConstructorName() { } \
|
||||
Value ConstructorName::call() \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue