From fd912a37a08c5ffaa1ca022ea6ca4114cb1e6aec Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 27 Apr 2018 09:39:24 +0200 Subject: [PATCH] stream: only check options once in Duplex ctor This commit updates the Duplex constructor adding an if statement checking if options is undefined, and removes the check from the following three if statements. PR-URL: https://github.com/nodejs/node/pull/20353 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- lib/_stream_duplex.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index b123cdcb4d7..7059757dbd4 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -50,17 +50,19 @@ function Duplex(options) { Readable.call(this, options); Writable.call(this, options); - - if (options && options.readable === false) - this.readable = false; - - if (options && options.writable === false) - this.writable = false; - this.allowHalfOpen = true; - if (options && options.allowHalfOpen === false) { - this.allowHalfOpen = false; - this.once('end', onend); + + if (options) { + if (options.readable === false) + this.readable = false; + + if (options.writable === false) + this.writable = false; + + if (options.allowHalfOpen === false) { + this.allowHalfOpen = false; + this.once('end', onend); + } } }