From 3d2794d062e3fd2497fa794b4f9238f2348a8d74 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 28 Feb 2024 11:20:01 -0500 Subject: [PATCH] LibJS: Add a fast path for setting valid u32 values in Uint32TypedArray The exisiting fast path only permits for valid i32 values. On https://cyxx.github.io/another_js, this eliminates the runtime of typed_array_set_element, and reduces the runtime of put_by_value from 11.1% to 7.7%. --- .../Libraries/LibJS/Bytecode/CommonImplementations.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 0f5831f578..17a0a4a509 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -443,6 +443,15 @@ inline ThrowCompletionOr put_by_value(VM& vm, Value base, Value property_k } } + if (typed_array.kind() == TypedArrayBase::Kind::Uint32Array && value.is_integral_number()) { + auto integer = value.as_double(); + + if (AK::is_within_range(integer) && is_valid_integer_index(typed_array, canonical_index)) { + fast_typed_array_set_element(typed_array, index, static_cast(integer)); + return {}; + } + } + switch (typed_array.kind()) { #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \ case TypedArrayBase::Kind::ClassName: \