LibJS: Add fast path for strings in Value::to_property_key()

If the Value is already a primitive string, we can skip all the
conversion ceremony and return a PropertyKey right away.
This commit is contained in:
Andreas Kling 2025-03-19 10:38:22 -05:00 committed by Andreas Kling
commit fc744e3f3f
Notes: github-actions[bot] 2025-03-24 22:28:32 +00:00

View file

@ -898,6 +898,10 @@ ThrowCompletionOr<PropertyKey> Value::to_property_key(VM& vm) const
if (is_int32() && as_i32() >= 0)
return PropertyKey { as_i32() };
// OPTIMIZATION: If this is already a string, we can skip all the ceremony.
if (is_string())
return PropertyKey { as_string().utf8_string() };
// 1. Let key be ? ToPrimitive(argument, string).
auto key = TRY(to_primitive(vm, PreferredType::String));