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:
parent
5951a93f51
commit
008b9f4c9f
1 changed files with 4 additions and 0 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue