Skip to content

Commit

Permalink
stream: avoid function call where possible
Browse files Browse the repository at this point in the history
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: #41488 (review)

PR-URL: #41534
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
Trott committed Jan 17, 2022
1 parent a7215c8 commit 20347d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/internal/streams/utils.js
Expand Up @@ -118,17 +118,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) {
Expand Down

0 comments on commit 20347d5

Please sign in to comment.