From b727f8113f9280e64e18dcbb0ed2921b19e51083 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 30 Mar 2023 18:42:25 +0200 Subject: [PATCH] LibJS: Add fast path to Value::to_u32() if Value is a positive i32 6.6% speed-up on Kraken's stanford-crypto-aes subtest. :^) --- Userland/Libraries/LibJS/Runtime/Value.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 660fe78bb2..90ed71024d 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -947,6 +947,10 @@ ThrowCompletionOr Value::to_i32(VM& vm) const // 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32 ThrowCompletionOr Value::to_u32(VM& vm) const { + // OPTIMIZATION: If this value is encoded as a positive i32, return it directly. + if (is_int32() && as_i32() >= 0) + return as_i32(); + // 1. Let number be ? ToNumber(argument). double number = TRY(to_number(vm)).as_double();