@@ -14,7 +14,6 @@ const { |
14 | 14 | ArrayBufferPrototypeSlice, |
15 | 15 | ArrayPrototypeMap, |
16 | 16 | ArrayPrototypePush, |
17 | | - ArrayPrototypeShift, |
18 | 17 | ArrayPrototypeSlice, |
19 | 18 | FunctionPrototypeCall, |
20 | 19 | ObjectFreeze, |
@@ -39,6 +38,7 @@ const { |
39 | 38 | }, |
40 | 39 | } = require('internal/errors'); |
41 | 40 | const { TextDecoder } = require('internal/encoding'); |
| 41 | +const { RingBuffer } = require('internal/streams/iter/ringbuffer'); |
42 | 42 | const { |
43 | 43 | validateFunction, |
44 | 44 | } = require('internal/validators'); |
@@ -516,7 +516,7 @@ function merge(...args) { |
516 | 516 | // between consumer pulls are drained synchronously without an extra |
517 | 517 | // async tick per batch. Each source has at most one pending .next() |
518 | 518 | // at a time. Every batch from every source is preserved. |
519 | | - const ready = []; |
| 519 | + const ready = new RingBuffer(); |
520 | 520 | const pendingPulls = new SafeSet(); |
521 | 521 | let activeCount = normalized.length; |
522 | 522 | let waitResolve = null; |
@@ -541,8 +541,7 @@ function merge(...args) { |
541 | 541 | if (result.done) { |
542 | 542 | activeCount--; |
543 | 543 | } else { |
544 | | - ArrayPrototypePush(ready, |
545 | | - new MergeEntry(iterator, result.value, undefined)); |
| 544 | + ready.push(new MergeEntry(iterator, result.value, undefined)); |
546 | 545 | } |
547 | 546 | if (waitResolve) { |
548 | 547 | waitResolve(); |
@@ -553,7 +552,7 @@ function merge(...args) { |
553 | 552 | const onRejected = (iterator, reason) => { |
554 | 553 | pendingPulls.delete(iterator); |
555 | 554 | if (stopped) return; |
556 | | - ArrayPrototypePush(ready, new MergeEntry(undefined, undefined, reason)); |
| 555 | + ready.push(new MergeEntry(undefined, undefined, reason)); |
557 | 556 | if (waitResolve) { |
558 | 557 | waitResolve(); |
559 | 558 | waitResolve = null; |
@@ -580,7 +579,7 @@ function merge(...args) { |
580 | 579 |
|
581 | 580 | // Drain ready queue synchronously |
582 | 581 | while (ready.length > 0) { |
583 | | - const item = ArrayPrototypeShift(ready); |
| 582 | + const item = ready.shift(); |
584 | 583 | if (item.iterator === undefined) { |
585 | 584 | throw item.reason; |
586 | 585 | } |
|