From 3e5aa9294a7599a10ccd2b31231b87dcb0fda81e Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 4 Jul 2021 07:14:22 -0400 Subject: [PATCH] stream: fix performance regression --- lib/internal/streams/duplex.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/internal/streams/duplex.js b/lib/internal/streams/duplex.js index 3d65c15f201dd7..29f25249b76c55 100644 --- a/lib/internal/streams/duplex.js +++ b/lib/internal/streams/duplex.js @@ -56,19 +56,23 @@ function Duplex(options) { Readable.call(this, options); Writable.call(this, options); - this.allowHalfOpen = options?.allowHalfOpen !== false; + if (options) { + this.allowHalfOpen = options.allowHalfOpen !== false; - if (options?.readable === false) { - this._readableState.readable = false; - this._readableState.ended = true; - this._readableState.endEmitted = true; - } + if (options.readable === false) { + this._readableState.readable = false; + this._readableState.ended = true; + this._readableState.endEmitted = true; + } - if (options?.writable === false) { - this._writableState.writable = false; - this._writableState.ending = true; - this._writableState.ended = true; - this._writableState.finished = true; + if (options.writable === false) { + this._writableState.writable = false; + this._writableState.ending = true; + this._writableState.ended = true; + this._writableState.finished = true; + } + } else { + this.allowHalfOpen = false; } }