mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +00:00
LibJS: Add fast path for add() with two numeric JS::Values
This commit is contained in:
parent
37cd1a95fc
commit
00965e3dad
1 changed files with 10 additions and 0 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue