LibJS: Add a fast-path to <Int32>.to_uint8()

This was showing up in a profile as hot.
This commit is contained in:
Ali Mohammad Pur 2025-08-01 18:31:39 +02:00 committed by Ali Mohammad Pur
commit 4e2845847b
Notes: github-actions[bot] 2025-08-08 10:56:11 +00:00

View file

@ -1050,6 +1050,11 @@ ThrowCompletionOr<i8> Value::to_i8(VM& vm) const
// 7.1.11 ToUint8 ( argument ), https://tc39.es/ecma262/#sec-touint8
ThrowCompletionOr<u8> Value::to_u8(VM& vm) const
{
// OPTIMIZATION: Fast path for the common case of an int32.
if (is_int32()) {
return static_cast<u8>(as_i32() & NumericLimits<u8>::max());
}
// 1. Let number be ? ToNumber(argument).
double number = TRY(to_number(vm)).as_double();