mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
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.
This commit is contained in:
parent
373ec387c1
commit
d8be9ebc16
1 changed files with 10 additions and 1 deletions
|
@ -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<i32>(index)), false);
|
||||
|
||||
auto value = TRY(array.get(index));
|
||||
auto value = TRY([&]() -> ThrowCompletionOr<Value> {
|
||||
// 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue