diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-24 16:27:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-24 17:18:09 +0200 |
commit | b138b4c83f7a1888f73451028f259e910c5a472f (patch) | |
tree | 8de73bf742965d562983a7ed51849812ceddaf7e /Userland/Libraries | |
parent | 65a7296b8f4431eea275b31c1490abd72b1af7c1 (diff) | |
download | serenity-b138b4c83f7a1888f73451028f259e910c5a472f.zip |
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. :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
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<double> Value::to_double(GlobalObject& global_object) const ThrowCompletionOr<PropertyKey> 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)); |