Skip to content

Commit

Permalink
stream: simplify clearBuffer condition
Browse files Browse the repository at this point in the history
Was doing some unecessary checks.
  • Loading branch information
ronag committed Apr 17, 2020
1 parent 38d9b7f commit 4ac87be
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function WritableState(options, stream, isDuplex) {
}

ObjectDefineProperties(WritableState.prototype, {
// Backwards compat.
writing: {
get() {
return !!this.writecb;
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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) {
clearBuffer(stream, state);
}

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4ac87be

Please sign in to comment.