From 4e2845847b47bfb2a83d4a6ee2cb97d5e400582b Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 1 Aug 2025 18:31:39 +0200 Subject: [PATCH] LibJS: Add a fast-path to .to_uint8() This was showing up in a profile as hot. --- Libraries/LibJS/Runtime/Value.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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();