diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index f7d7387f78f..681c39853ba 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -1050,6 +1050,11 @@ ThrowCompletionOr Value::to_i8(VM& vm) const // 7.1.11 ToUint8 ( argument ), https://tc39.es/ecma262/#sec-touint8 ThrowCompletionOr Value::to_u8(VM& vm) const { + // OPTIMIZATION: Fast path for the common case of an int32. + if (is_int32()) { + return static_cast(as_i32() & NumericLimits::max()); + } + // 1. Let number be ? ToNumber(argument). double number = TRY(to_number(vm)).as_double();