GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: use a RingBuffer for stream/iter merge()'s ready queue · nodejs/node@9c6caaf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • consumers.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/consumers.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/consumers.js
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
ArrayBufferPrototypeSlice,
1515
ArrayPrototypeMap,
1616
ArrayPrototypePush,
17-
ArrayPrototypeShift,
1817
ArrayPrototypeSlice,
1918
FunctionPrototypeCall,
2019
ObjectFreeze,
@@ -39,6 +38,7 @@ const {
3938
},
4039
} = require('internal/errors');
4140
const { TextDecoder } = require('internal/encoding');
41+
const { RingBuffer } = require('internal/streams/iter/ringbuffer');
4242
const {
4343
validateFunction,
4444
} = require('internal/validators');
@@ -516,7 +516,7 @@ function merge(...args) {
516516
// between consumer pulls are drained synchronously without an extra
517517
// async tick per batch. Each source has at most one pending .next()
518518
// at a time. Every batch from every source is preserved.
519-
const ready = [];
519+
const ready = new RingBuffer();
520520
const pendingPulls = new SafeSet();
521521
let activeCount = normalized.length;
522522
let waitResolve = null;
@@ -541,8 +541,7 @@ function merge(...args) {
541541
if (result.done) {
542542
activeCount--;
543543
} else {
544-
ArrayPrototypePush(ready,
545-
new MergeEntry(iterator, result.value, undefined));
544+
ready.push(new MergeEntry(iterator, result.value, undefined));
546545
}
547546
if (waitResolve) {
548547
waitResolve();
@@ -553,7 +552,7 @@ function merge(...args) {
553552
const onRejected = (iterator, reason) => {
554553
pendingPulls.delete(iterator);
555554
if (stopped) return;
556-
ArrayPrototypePush(ready, new MergeEntry(undefined, undefined, reason));
555+
ready.push(new MergeEntry(undefined, undefined, reason));
557556
if (waitResolve) {
558557
waitResolve();
559558
waitResolve = null;
@@ -580,7 +579,7 @@ function merge(...args) {
580579

581580
// Drain ready queue synchronously
582581
while (ready.length > 0) {
583-
const item = ArrayPrototypeShift(ready);
582+
const item = ready.shift();
584583
if (item.iterator === undefined) {
585584
throw item.reason;
586585
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.