mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +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:
@@ -49,15 +49,16 @@ Function::~Function()
|
||||
|
||||
BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
Function& target_function = is_bound_function() ? static_cast<BoundFunction&>(*this).target_function() : *this;
|
||||
|
||||
auto bound_this_object = [bound_this_value, this]() -> Value {
|
||||
auto bound_this_object = [&vm, bound_this_value, this]() -> Value {
|
||||
if (!m_bound_this.is_empty())
|
||||
return m_bound_this;
|
||||
switch (bound_this_value.type()) {
|
||||
case Value::Type::Undefined:
|
||||
case Value::Type::Null:
|
||||
if (vm().in_strict_mode())
|
||||
if (vm.in_strict_mode())
|
||||
return bound_this_value;
|
||||
return &global_object();
|
||||
default:
|
||||
@@ -66,15 +67,15 @@ BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments)
|
||||
}();
|
||||
|
||||
i32 computed_length = 0;
|
||||
auto length_property = get("length");
|
||||
if (vm().exception())
|
||||
auto length_property = get(vm.names.length);
|
||||
if (vm.exception())
|
||||
return nullptr;
|
||||
if (length_property.is_number())
|
||||
computed_length = max(0, length_property.as_i32() - static_cast<i32>(arguments.size()));
|
||||
|
||||
Object* constructor_prototype = nullptr;
|
||||
auto prototype_property = target_function.get("prototype");
|
||||
if (vm().exception())
|
||||
auto prototype_property = target_function.get(vm.names.prototype);
|
||||
if (vm.exception())
|
||||
return nullptr;
|
||||
if (prototype_property.is_object())
|
||||
constructor_prototype = &prototype_property.as_object();
|
||||
|
||||
Reference in New Issue
Block a user