mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
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:
parent
1662223e89
commit
fc744e3f3f
|
|
@ -898,6 +898,10 @@ ThrowCompletionOr<PropertyKey> Value::to_property_key(VM& vm) const
|
||||||
if (is_int32() && as_i32() >= 0)
|
if (is_int32() && as_i32() >= 0)
|
||||||
return PropertyKey { as_i32() };
|
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).
|
// 1. Let key be ? ToPrimitive(argument, string).
|
||||||
auto key = TRY(to_primitive(vm, PreferredType::String));
|
auto key = TRY(to_primitive(vm, PreferredType::String));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user