mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +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
|
@ -79,8 +79,14 @@ void MathObject::initialize(Realm& realm)
|
|||
// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.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).
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
auto number = TRY(x.to_number(vm));
|
||||
|
||||
// 2. If n is NaN, return NaN.
|
||||
if (number.is_nan())
|
||||
|
|
Loading…
Reference in a new issue