From 40ffed8f3f4392d6e110769ca06d86d6295fc645 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 22 Jan 2015 20:46:43 -0500 Subject: [PATCH] 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: https://github.com/iojs/io.js/pull/564 Reviewed-By: Ben Noordhuis Reviewed-By: Jeremiah Senkpiel --- lib/_stream_writable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 1db43dac83cafc..a3c65f45951800 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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; @@ -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);