stream: use nop as write() callback if omitted
authorcjihrig <cjihrig@gmail.com>
Fri, 23 Jan 2015 01:46:43 +0000 (20:46 -0500)
committercjihrig <cjihrig@gmail.com>
Fri, 23 Jan 2015 14:43:31 +0000 (09:43 -0500)
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 <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
lib/_stream_writable.js

index 1db43da..a3c65f4 100644 (file)
@@ -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);