Skip to content

Commit 40ffed8

Browse files
committed
stream: use nop as write() callback if omitted
This commit introduces a nop function that is used as the Writable.prototype.write() callback when one is not provided. This saves on function object creation. PR-URL: #564 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent df0d790 commit 40ffed8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/_stream_writable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const debug = util.debuglog('stream');
1313

1414
util.inherits(Writable, Stream);
1515

16+
function nop() {}
17+
1618
function WriteReq(chunk, encoding, cb) {
1719
this.chunk = chunk;
1820
this.encoding = encoding;
@@ -189,7 +191,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
189191
encoding = state.defaultEncoding;
190192

191193
if (!util.isFunction(cb))
192-
cb = function() {};
194+
cb = nop;
193195

194196
if (state.ended)
195197
writeAfterEnd(this, state, cb);

0 commit comments

Comments
 (0)