aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiklos Suveges <miklos.suveges@gmail.com>2018-05-29 01:47:27 +0200
committerMatteo Collina <hello@matteocollina.com>2018-06-02 14:18:40 +0200
commit1c07ebfd97bf4d10a6c9220f12eb476c174ab3b0 (patch)
tree2219c9183df761614ed61f797702092233916d4b /lib
parentf86e5fc4370fb21c39109bcf388e0f25963b1832 (diff)
downloadandroid-node-v8-1c07ebfd97bf4d10a6c9220f12eb476c174ab3b0.tar.gz
android-node-v8-1c07ebfd97bf4d10a6c9220f12eb476c174ab3b0.tar.bz2
android-node-v8-1c07ebfd97bf4d10a6c9220f12eb476c174ab3b0.zip
stream: inline needMoreData function
Inline the needMoreData function since it has only one call place. Update the related comment. Add a test for the edge case where HWM=0 and state.length=0. Add a test for ReadableStream.read(n) method's edge case where n, HWM and state.length are all zero. This proves that there is no easy way to simplify the check at https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L440 Fixes: https://github.com/nodejs/node/issues/19893 Refs: https://github.com/nodejs/node/pull/19896 PR-URL: https://github.com/nodejs/node/pull/21009 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Lance Ball <lball@redhat.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_stream_readable.js19
1 files changed, 5 insertions, 14 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index a8e52f5f1d..31b129facd 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -270,7 +270,11 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
}
}
- return needMoreData(state);
+ // We can push more data if we are below the highWaterMark.
+ // Also, if we have no data yet, we can stand some more bytes.
+ // This is to work around cases where hwm=0, such as the repl.
+ return !state.ended &&
+ (state.length < state.highWaterMark || state.length === 0);
}
function addChunk(stream, state, chunk, addToFront) {
@@ -304,19 +308,6 @@ function chunkInvalid(state, chunk) {
}
-// We can push more data if we are below the highWaterMark.
-// Also, if we have no data yet, we can stand some
-// more bytes. This is to work around cases where hwm=0,
-// such as the repl. Also, if the push() triggered a
-// readable event, and the user called read(largeNumber) such that
-// needReadable was set, then we ought to push more, so that another
-// 'readable' event will be triggered.
-function needMoreData(state) {
- return !state.ended &&
- (state.length < state.highWaterMark ||
- state.length === 0);
-}
-
Readable.prototype.isPaused = function() {
return this._readableState.flowing === false;
};