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
functionisReadable(stream){
120120
if(stream&&stream[kIsReadable]!=null)returnstream[kIsReadable];
121-
constr=isReadableNodeStream(stream);
122121
if(typeofstream?.readable!=='boolean')returnnull;
123122
if(isDestroyed(stream))returnfalse;
124-
returnr&&stream.readable&&!isReadableFinished(stream);
123+
returnisReadableNodeStream(stream)&&
124+
stream.readable&&
125+
!isReadableFinished(stream);
125126
}
126127

127128
functionisWritable(stream){
128-
constr=isWritableNodeStream(stream);
129129
if(typeofstream?.writable!=='boolean')returnnull;
130130
if(isDestroyed(stream))returnfalse;
131-
returnr&&stream.writable&&!isWritableEnded(stream);
131+
returnisWritableNodeStream(stream)&&
132+
stream.writable&&
133+
!isWritableEnded(stream);
132134
}
133135

134136
functionisFinished(stream,opts){

0 commit comments

Comments
(0)