mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 08:17:35 +00:00
LibJS: Add fast-path for Int32 values in Math.abs()
This function becomes very simple when the input is already an Int32. 2.3% speed-up on Kraken/imaging-gaussian-blur.js :^)
This commit is contained in:
parent
b53a633388
commit
14a9cfef4d
1 changed files with 7 additions and 1 deletions
|
@ -79,8 +79,14 @@ void MathObject::initialize(Realm& realm)
|
||||||
// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs
|
// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
|
||||||
{
|
{
|
||||||
|
auto x = vm.argument(0);
|
||||||
|
|
||||||
|
// OPTIMIZATION: Fast path for Int32 values.
|
||||||
|
if (x.is_int32())
|
||||||
|
return Value(AK::abs(x.as_i32()));
|
||||||
|
|
||||||
// Let n be ? ToNumber(x).
|
// Let n be ? ToNumber(x).
|
||||||
auto number = TRY(vm.argument(0).to_number(vm));
|
auto number = TRY(x.to_number(vm));
|
||||||
|
|
||||||
// 2. If n is NaN, return NaN.
|
// 2. If n is NaN, return NaN.
|
||||||
if (number.is_nan())
|
if (number.is_nan())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue