From 4ac87beb6d0f8b6693fc8792229f814f64ef92bd Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 17 Apr 2020 09:11:24 +0200 Subject: [PATCH] stream: simplify clearBuffer condition Was doing some unecessary checks. --- lib/_stream_writable.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 7ae67bd8b1d1e1..dde0abee2d19f1 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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) { 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;