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: some simplification #32900

Closed
wants to merge 4 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
Prev Previous commit
Next Next commit
stream: simplify clearBuffer condition
Was doing some unecessary checks.
  • Loading branch information
ronag committed Apr 17, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4ac87beb6d0f8b6693fc8792229f814f64ef92bd
22 changes: 10 additions & 12 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
@@ -186,6 +186,7 @@ function WritableState(options, stream, isDuplex) {
}

ObjectDefineProperties(WritableState.prototype, {
// Backwards compat.
writing: {
get() {
return !!this.writecb;
@@ -323,11 +324,7 @@ Writable.prototype.uncork = function() {
if (state.corked) {
state.corked--;

if (!state.writecb &&
!state.corked &&
!state.bufferProcessing &&
state.bufferedRequest)
clearBuffer(this, state);
clearBuffer(this, state);
}
};

@@ -432,13 +429,7 @@ function onwrite(stream, er) {
onwriteError(stream, state, er, cb);
}
} else {
// Check if we're actually ready to finish, but don't emit yet
const finished = needFinish(state) || stream.destroyed;

if (!finished &&
!state.corked &&
!state.bufferProcessing &&
state.bufferedRequest) {
if (state.bufferedRequest) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This condition is a duplicate of what's inside of clearBuffer. However, it is here on purpose since clearBuffer is not inlineable.

clearBuffer(stream, state);
}

@@ -503,6 +494,13 @@ function errorBuffer(state, err) {

// If there's something in the buffer waiting, then process it
function clearBuffer(stream, state) {
if (state.writecb ||
state.corked ||
state.bufferProcessing ||
!state.bufferedRequest) {
return;
}

state.bufferProcessing = true;
let entry = state.bufferedRequest;