mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/pull/41488#pullrequestreview-850626528 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user