Skip to content

Commit 1425e75

Browse files
Trottdanielleadams
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 ec72cb4 commit 1425e75

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
@@ -113,17 +113,19 @@ function isReadableFinished(stream, strict) {
113113

114114
function isReadable(stream) {
115115
if (stream && stream[kIsReadable] != null) return stream[kIsReadable];
116-
const r = isReadableNodeStream(stream);
117116
if (typeof stream?.readable !== 'boolean') return null;
118117
if (isDestroyed(stream)) return false;
119-
return r && stream.readable && !isReadableFinished(stream);
118+
return isReadableNodeStream(stream) &&
119+
stream.readable &&
120+
!isReadableFinished(stream);
120121
}
121122

122123
function isWritable(stream) {
123-
const r = isWritableNodeStream(stream);
124124
if (typeof stream?.writable !== 'boolean') return null;
125125
if (isDestroyed(stream)) return false;
126-
return r && stream.writable && !isWritableEnded(stream);
126+
return isWritableNodeStream(stream) &&
127+
stream.writable &&
128+
!isWritableEnded(stream);
127129
}
128130

129131
function isFinished(stream, opts) {

0 commit comments

Comments
 (0)