1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibJS: Add fast-path for Value::to_numeric() on number values

We can skip a whole bunch of checks in this case and just return the
value itself.

2% speed-up on Kraken/imaging-darkroom.js :^)
This commit is contained in:
Andreas Kling 2023-09-03 18:07:27 +02:00
parent 5951a93f51
commit 008b9f4c9f

View file

@ -587,6 +587,10 @@ ThrowCompletionOr<NonnullGCPtr<Object>> Value::to_object(VM& vm) const
// 7.1.3 ToNumeric ( value ), https://tc39.es/ecma262/#sec-tonumeric
FLATTEN ThrowCompletionOr<Value> Value::to_numeric(VM& vm) const
{
// OPTIMIZATION: Fast path for when this value is already a number.
if (is_number())
return *this;
// 1. Let primValue be ? ToPrimitive(value, number).
auto primitive_value = TRY(to_primitive(vm, Value::PreferredType::Number));