Procházet zdrojové kódy

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. :^)
Andreas Kling před 3 roky
rodič
revize
b138b4c83f
1 změnil soubory, kde provedl 2 přidání a 0 odebrání
  1. 2 0
      Userland/Libraries/LibJS/Runtime/Value.cpp

+ 2 - 0
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));