Skip to content

Commit 9226322

Browse files
TrottBethGriggs
authored andcommitted
stream: avoid function call where possible
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 878b2e7 commit 9226322

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/internal/streams/utils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,19 @@ function isReadableFinished(stream, strict) {
118118

119119
function isReadable(stream) {
120120
if (stream && stream[kIsReadable] != null) return stream[kIsReadable];
121-
const r = isReadableNodeStream(stream);
122121
if (typeof stream?.readable !== 'boolean') return null;
123122
if (isDestroyed(stream)) return false;
124-
return r && stream.readable && !isReadableFinished(stream);
123+
return isReadableNodeStream(stream) &&
124+
stream.readable &&
125+
!isReadableFinished(stream);
125126
}
126127

127128
function isWritable(stream) {
128-
const r = isWritableNodeStream(stream);
129129
if (typeof stream?.writable !== 'boolean') return null;
130130
if (isDestroyed(stream)) return false;
131-
return r && stream.writable && !isWritableEnded(stream);
131+
return isWritableNodeStream(stream) &&
132+
stream.writable &&
133+
!isWritableEnded(stream);
132134
}
133135

134136
function isFinished(stream, opts) {

0 commit comments

Comments
 (0)