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 1 commit
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
5 changes: 2 additions & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ function chunkInvalid(state, chunk) {
// 'readable' event will be triggered.
function needMoreData(state) {
return !state.ended &&
(state.length < state.highWaterMark ||
state.length === 0);
(state.length < 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.

Suggestion: this function could be inlined. It only has a single call site.

Copy link
Member

Choose a reason for hiding this comment

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

Also needs to be <= as above

Copy link
Contributor Author

@vishal7201 vishal7201 Apr 11, 2018

Choose a reason for hiding this comment

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

with <= , a test case is failing AssertionError [ERR_ASSERTION]: true strictEqual false at Object.<anonymous> (node/test/parallel/test-stream2-objects.js:212:12)

Copy link
Member

Choose a reason for hiding this comment

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

True, this is ok.

Copy link
Member

Choose a reason for hiding this comment

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

can you remove the parenthesis? They are not needed anymore.

Copy link
Member

Choose a reason for hiding this comment

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

can prob also be a one liner as this looks like it's <80 chars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. I will do that


Readable.prototype.isPaused = function() {
Expand Down Expand Up @@ -434,7 +433,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