mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibJS+LibWeb: Add fast path for builtin iterators in iterator_step()
We already have fast path for built-in iterators that skips `next()`
lookup and iteration result object allocation applied for `for..of` and
`for..in` loops. This change extends it to `iterator_step()` to cover
`Array.from()`, `[...arr]` and many other cases.
Makes following function go 2.35x faster on my computer:
```js
(function f() {
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < 1000000; i++) {
let [a, ...rest] = arr;
}
})();
```
This commit is contained in:
committed by
Alexander Kalenik
parent
31301ef08b
commit
bb53485dea
Notes:
github-actions[bot]
2025-05-13 12:15:28 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/bb53485dea1 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4704
@@ -346,12 +346,12 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
|
||||
auto next = TRY(JS::iterator_step(vm, iter));
|
||||
|
||||
// 3. If next is false abort this loop.
|
||||
if (!next)
|
||||
if (!next.has<JS::IterationResult>())
|
||||
break;
|
||||
|
||||
// 4. Let nextItem be IteratorValue(next).
|
||||
// 5. Check the completion record of nextItem.
|
||||
auto next_item = TRY(JS::iterator_value(vm, *next));
|
||||
auto next_item = TRY(next.get<JS::IterationResult>().value);
|
||||
|
||||
// 6. If Type(nextItem) is not Undefined, Null or Object, then throw a TypeError and abort these steps.
|
||||
if (!next_item.is_nullish() && !next_item.is_object())
|
||||
|
||||
Reference in New Issue
Block a user