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

stream: simplify checks for highWaterMark #19893

Closed
mcollina opened this issue Apr 9, 2018 · 5 comments
Closed

stream: simplify checks for highWaterMark #19893

mcollina opened this issue Apr 9, 2018 · 5 comments
Labels
good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.

Comments

@mcollina
Copy link
Member

mcollina commented Apr 9, 2018

  • Version: master
  • Platform: all
  • Subsystem: stream

In lib/_streams_readable.js, we have a block of code like this:

          (state.length < state.highWaterMark ||
           state.length === 0);

Because state.highWaterMark  could be < 0 or null or undefined or really any object in Node < 10. However, we landed #18098 and so now we can simplify all those checks to be state.length <= state.highWaterMark.

@mcollina mcollina added stream Issues and PRs related to the stream subsystem. good first issue Issues that are suitable for first-time contributors. labels Apr 9, 2018
@dicearr
Copy link
Contributor

dicearr commented Apr 9, 2018

So line lib/_streams_readable.js#314 and line lib/_streams_readable.js#437 needs to be replaced. Removing state.length === 0 and replacing < with <=. Am I right?

@sagirk
Copy link
Contributor

sagirk commented Apr 9, 2018

@mcollina If no one is already working on this, I would like to volunteer. First-time node contributor.

@vishal7201
Copy link
Contributor

@sagirk I have started working on the issue

@trivikr trivikr mentioned this issue Apr 15, 2018
4 tasks
@bakpatrycja
Copy link

i also have started to work on it

kodemill added a commit to kodemill/node that referenced this issue May 28, 2018
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
@kodemill
Copy link
Contributor

@mcollina @vishal7201 I made some progress on this, since it looked like it was orphaned.
@RoGalinka sorry, I just missed your comment.

MylesBorins pushed a commit that referenced this issue Jun 6, 2018
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants