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: delete redundant code #18145

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
11 changes: 4 additions & 7 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ Writable.prototype.uncork = function() {

if (!state.writing &&
!state.corked &&
!state.finished &&
Copy link
Member

Choose a reason for hiding this comment

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

why is this unused?

Copy link
Member Author

Choose a reason for hiding this comment

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

state.finished should equal false if state.bufferedRequest isn't null.

!state.bufferProcessing &&
state.bufferedRequest)
clearBuffer(this, state);
Expand Down Expand Up @@ -579,7 +578,7 @@ Writable.prototype.end = function(chunk, encoding, cb) {
}

// ignore unnecessary end() calls.
if (!state.ending && !state.finished)
if (!state.ending)
Copy link
Member

Choose a reason for hiding this comment

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

This is actually a behavior change. Can you add a unit test?

Copy link
Member Author

@MoonBall MoonBall Jan 17, 2018

Choose a reason for hiding this comment

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

state.finished = true is only in finishMaybe(). If we simplify the finishMaybe(), it should be:

function finishMaybe(stream, state) {
  if (state.ending) {
    state.finished = true;
  }
}

And, state.ending doesn't set to false.
So:

  1. if state.finished is true, state.ending must be true:
    !state.ending && !state.finished equals false && false.
    !state.ending equals false.
    !state.ending && !state.finished equals !state.ending.
  2. if state.finished is false:
    !state.ending && !state.finished equals !state.ending && true.
    !state.ending && !state.finished equals !state.ending.

endWritable(this, state, cb);
};

Expand Down Expand Up @@ -658,11 +657,9 @@ function onCorkedFinish(corkReq, state, err) {
cb(err);
entry = entry.next;
}
if (state.corkedRequestsFree) {
state.corkedRequestsFree.next = corkReq;
} else {
state.corkedRequestsFree = corkReq;
}

// reuse the free corkReq.
state.corkedRequestsFree.next = corkReq;
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, this can end up being null because it copied over in: https://github.com/MoonBall/node/blob/dd13a79b830ef2d33ac0288e197a431a63e40941/lib/_stream_writable.js#L517. Can you revert this?

Copy link
Member Author

@MoonBall MoonBall Jan 17, 2018

Choose a reason for hiding this comment

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

if (holder.next) can ensure that state.corkedRequestsFree is not null.

Copy link
Member

Choose a reason for hiding this comment

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

My bad. I'm very scared of #6164 and #6154

}

Object.defineProperty(Writable.prototype, 'destroyed', {
Expand Down