mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
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. :^)
This commit is contained in:
parent
65a7296b8f
commit
b138b4c83f
1 changed files with 2 additions and 0 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue