Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 557044a

Browse filesBrowse files
authored
stream: avoid unnecessary drain for sync stream
PR-URL: #50014 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 95b8f5d commit 557044a
Copy full SHA for 557044a

File tree

Expand file treeCollapse file tree

2 files changed

+12
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-9
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/transform.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/transform.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ Transform.prototype._write = function(chunk, encoding, callback) {
182182
this.push(val);
183183
}
184184

185-
if (
185+
if (rState.ended) {
186+
// If user has called this.push(null) we have to
187+
// delay the callback to properly progate the new
188+
// state.
189+
process.nextTick(callback);
190+
} else if (
186191
wState.ended || // Backwards compat.
187192
length === rState.length || // Backwards compat.
188193
rState.length < rState.highWaterMark
Collapse file

‎lib/internal/streams/writable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,6 @@ function writeOrBuffer(stream, state, chunk, encoding, callback) {
517517

518518
state.length += len;
519519

520-
// stream._write resets state.length
521-
const ret = state.length < state.highWaterMark;
522-
523-
// We must ensure that previous needDrain will not be reset to false.
524-
if (!ret) {
525-
state.state |= kNeedDrain;
526-
}
527-
528520
if ((state.state & (kWriting | kErrored | kCorked | kConstructed)) !== kConstructed) {
529521
state.buffered.push({ chunk, encoding, callback });
530522
state.state |= kHasBuffer;
@@ -544,6 +536,12 @@ function writeOrBuffer(stream, state, chunk, encoding, callback) {
544536
state.state &= ~kSync;
545537
}
546538

539+
const ret = state.length < state.highWaterMark;
540+
541+
if (!ret) {
542+
state.state |= kNeedDrain;
543+
}
544+
547545
// Return false if errored or destroyed in order to break
548546
// any synchronous while(stream.write(data)) loops.
549547
return ret && (state.state & (kDestroyed | kErrored)) === 0;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.