From a5ba28dda2c2ff0eb3201169ad3cf46d960e0c13 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 PR-URL: https://github.com/nodejs/node/pull/39254 Reviewed-By: Yongsheng Zhang Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- 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..6916f954ac48c3 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 = true; } }