From b138b4c83f7a1888f73451028f259e910c5a472f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Oct 2021 16:27:32 +0200 Subject: LibJS: Optimize Value::to_property_key() for numeric property names If the Value is a non-negative Int32, create a numeric PropertyKey instead of making a string key. This makes "ai-astar" test from the Kraken benchmark run in 30 seconds, down from 42 seconds. :^) --- Userland/Libraries/LibJS/Runtime/Value.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 2e059e092f..9e7275bb30 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -562,6 +562,8 @@ ThrowCompletionOr Value::to_double(GlobalObject& global_object) const ThrowCompletionOr Value::to_property_key(GlobalObject& global_object) const { auto key = TRY(to_primitive(global_object, PreferredType::String)); + if (key.type() == Type::Int32 && key.as_i32() >= 0) + return PropertyKey { key.as_i32() }; if (key.is_symbol()) return &key.as_symbol(); return TRY(key.to_string(global_object)); -- cgit v1.2.3