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)
  • Loading branch information
Trott committed Jan 15, 2022
1 parent f7be6ab commit 2b443be
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 2b443be

Please sign in to comment.