Skip to content

Commit e0f819d

Browse files
committed
stream: optimize single-slot push queue drain
Avoid allocating a new result array when PushQueue drains a single queued slot. Return that slot directly and keep the existing flattening path for multiple queued slots. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent a37c61d commit e0f819d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/internal/streams/iter/push.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ class PushQueue {
448448
// ===========================================================================
449449

450450
#drain() {
451+
if (this.#slots.length === 1) {
452+
return this.#slots.shift();
453+
}
454+
451455
const result = [];
452456
for (let i = 0; i < this.#slots.length; i++) {
453457
const slot = this.#slots.get(i);

0 commit comments

Comments
 (0)