-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
code cleanup #19896
Conversation
lib/_stream_readable.js
Outdated
(state.needReadable || | ||
state.length < state.highWaterMark || | ||
state.length === 0); | ||
(state.needReadable || state.length < state.highWaterMark); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can state.highWaterMark
be 0
? If so, <
should probably be <=
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be <=
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add a test for this case.
cc @nodejs/streams |
@vishal7201 seems like something went wrong when updating your PR. Would you mind to rebase? :-) |
lib/_stream_readable.js
Outdated
@@ -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); | |||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, this is ok.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…highWaterMark (needMoreData function)
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @MoonBall
This appears to be a fix for #19893
|
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: nodejs#19893 Refs: nodejs#19896
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: #19893 Refs: #19896 PR-URL: #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>
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: #19893 Refs: #19896 PR-URL: #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>
I'm going to close this out given that this has had no follow up in two months and there are issues with it, as expressed abbove. @vishal7201 please feel free to reopen if you would like to follow up on this! |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes