From 1425e75093799f8ce5325f2f341fc5864f84ab17 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 16 Jan 2022 21:31:30 -0800 Subject: [PATCH] stream: avoid function call where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of assigning a boolean, move the function call that assigns a value to the boolean to the only place that boolean is checked. This avoids the function call in cases where it is not needed. Refs: https://github.com/nodejs/node/pull/41488#pullrequestreview-850626528 PR-URL: https://github.com/nodejs/node/pull/41534 Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Gerhard Stöbich Reviewed-By: Matteo Collina --- lib/internal/streams/utils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/internal/streams/utils.js b/lib/internal/streams/utils.js index 1b317eeb7e5cb5..b72fb93b67740d 100644 --- a/lib/internal/streams/utils.js +++ b/lib/internal/streams/utils.js @@ -113,17 +113,19 @@ function isReadableFinished(stream, strict) { function isReadable(stream) { if (stream && stream[kIsReadable] != null) return stream[kIsReadable]; - const r = isReadableNodeStream(stream); if (typeof stream?.readable !== 'boolean') return null; if (isDestroyed(stream)) return false; - return r && stream.readable && !isReadableFinished(stream); + return isReadableNodeStream(stream) && + stream.readable && + !isReadableFinished(stream); } function isWritable(stream) { - const r = isWritableNodeStream(stream); if (typeof stream?.writable !== 'boolean') return null; if (isDestroyed(stream)) return false; - return r && stream.writable && !isWritableEnded(stream); + return isWritableNodeStream(stream) && + stream.writable && + !isWritableEnded(stream); } function isFinished(stream, opts) {