diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 1de8d6d935..b3c60b31c6 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021-2024, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -1045,7 +1045,18 @@ ThrowCompletionOr Return::execute_impl(Bytecode::Interpreter& interpreter) ThrowCompletionOr Increment::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); - auto old_value = TRY(interpreter.accumulator().to_numeric(vm)); + auto old_value = interpreter.accumulator(); + + // OPTIMIZATION: Fast path for Int32 values. + if (old_value.is_int32()) { + auto integer_value = old_value.as_i32(); + if (integer_value != NumericLimits::max()) [[likely]] { + interpreter.accumulator() = Value { integer_value + 1 }; + return {}; + } + } + + old_value = TRY(old_value.to_numeric(vm)); if (old_value.is_number()) interpreter.accumulator() = Value(old_value.as_double() + 1);