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: nodejs#41488 (review)

PR-URL: nodejs#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 authored and thedull committed Jan 18, 2022
1 parent 25eb907 commit c7e1826
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
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 c7e1826

Please sign in to comment.