1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 12:08:14 +00:00

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.
This commit is contained in:
Andreas Kling 2021-06-13 18:59:07 +02:00
parent 53a8a11973
commit 5eef07d232
25 changed files with 84 additions and 58 deletions

View file

@ -331,7 +331,7 @@ void VM::assign(const NonnullRefPtr<BindingPattern>& target, Value value, Global
Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
{
if (!m_call_stack.is_empty()) {
if (name == names.arguments && !call_frame().callee.is_empty()) {
if (name == names.arguments.as_string() && !call_frame().callee.is_empty()) {
// HACK: Special handling for the name "arguments":
// If the name "arguments" is defined in the current scope, for example via
// a function parameter, or by a local var declaration, we use that.