1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibJS: Add fast path for add() with two numeric JS::Values

This commit is contained in:
Andreas Kling 2021-03-21 18:13:14 +01:00
parent 37cd1a95fc
commit 00965e3dad

View file

@ -833,6 +833,16 @@ Value unsigned_right_shift(GlobalObject& global_object, Value lhs, Value rhs)
Value add(GlobalObject& global_object, Value lhs, Value rhs)
{
if (both_number(lhs, rhs)) {
if (lhs.type() == Value::Type::Int32 && rhs.type() == Value::Type::Int32) {
Checked<i32> result;
result = lhs.to_i32(global_object);
result += rhs.to_i32(global_object);
if (!result.has_overflow())
return Value(result.value());
}
return Value(lhs.as_double() + rhs.as_double());
}
auto& vm = global_object.vm();
auto lhs_primitive = lhs.to_primitive(global_object);
if (vm.exception())