Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup #19896

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ function chunkInvalid(state, chunk) {
// 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);
return !state.ended && state.length <= state.highWaterMark;
}

Readable.prototype.isPaused = function() {
Expand Down Expand Up @@ -434,7 +432,7 @@ Readable.prototype.read = function(n) {
debug('need readable', doRead);

// if we currently have less than the highWaterMark, then also read some
if (state.length === 0 || state.length - n < state.highWaterMark) {
if (state.length - n < state.highWaterMark) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that state.highWaterMark, state.length and n maybe equal 0. So if they all equal 0, state.length - n < state.highWaterMark doesn't equal to state.length === 0 || state.length - n < state.highWaterMark.

I suggest that this change would be with another PR because code cleaning shouldn't change code logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @MoonBall

doRead = true;
debug('length less than watermark', doRead);
}
Expand Down