Skip to content

Commit

Permalink
stream: use nop as write() callback if omitted
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig committed Jan 23, 2015
1 parent df0d790 commit 40ffed8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const debug = util.debuglog('stream');

util.inherits(Writable, Stream);

function nop() {}

function WriteReq(chunk, encoding, cb) {
this.chunk = chunk;
this.encoding = encoding;
Expand Down Expand Up @@ -189,7 +191,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
encoding = state.defaultEncoding;

if (!util.isFunction(cb))
cb = function() {};
cb = nop;

if (state.ended)
writeAfterEnd(this, state, cb);
Expand Down

0 comments on commit 40ffed8

Please sign in to comment.