From d8be9ebc1601ad5a26a12ad1f46a1632da398c84 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 Dec 2023 12:50:44 +0100 Subject: [PATCH] LibJS: Add fast path in ArrayIteratorPrototype::next() When iterating over vanilla objects/arrays with normal property storage, we can skip the generic Get mechanism in favor of looking directly at property storage. This is essentially what we do in the bytecode path. --- .../LibJS/Runtime/ArrayIteratorPrototype.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index 3dcc9ada4d..470c3033ce 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -70,7 +70,16 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) if (iteration_kind == Object::PropertyKind::Key) return create_iterator_result_object(vm, Value(static_cast(index)), false); - auto value = TRY(array.get(index)); + auto value = TRY([&]() -> ThrowCompletionOr { + // OPTIMIZATION: For objects that don't interfere with indexed property access, we try looking directly at storage. + if (!array.may_interfere_with_indexed_property_access() && array.indexed_properties().has_index(index)) { + auto value = array.indexed_properties().get(index)->value; + if (!value.is_accessor()) { + return value; + } + } + return array.get(index); + }()); if (iteration_kind == Object::PropertyKind::Value) return create_iterator_result_object(vm, value, false);