From cca8de6709ece5b4791d52a8b834da83bfb782d5 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 23 Sep 2014 23:08:35 -0400 Subject: [PATCH] net: remove use of arguments in Server constructor The current implementation uses the arguments object in the Server() constructor. Since both arguments to Server() are optional, there was a high likelihood of accessing a non-existent element in arguments, which carries a performance overhead. This commit replaces the arguments object with named arguments. Reviewed-by: Trevor Norris Conflicts: lib/net.js --- lib/net.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/net.js b/lib/net.js index 294c7f99ee6a7e..9f566b684d46ce 100644 --- a/lib/net.js +++ b/lib/net.js @@ -48,8 +48,8 @@ function isPipeName(s) { return typeof s === 'string' && toNumber(s) === false; } -exports.createServer = function() { - return new Server(arguments[0], arguments[1]); +exports.createServer = function(options, connectionListener) { + return new Server(options, connectionListener); }; @@ -991,22 +991,24 @@ function afterConnect(status, handle, req, readable, writable) { } -function Server(/* [ options, ] listener */) { - if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]); +function Server(options, connectionListener) { + if (!(this instanceof Server)) + return new Server(options, connectionListener); + events.EventEmitter.call(this); var self = this; - var options; - if (typeof arguments[0] === 'function') { + if (typeof options === 'function') { + connectionListener = options; options = {}; - self.on('connection', arguments[0]); + self.on('connection', connectionListener); } else { - options = arguments[0] || {}; + options = options || {}; - if (typeof arguments[1] === 'function') { - self.on('connection', arguments[1]); + if (typeof connectionListener === 'function') { + self.on('connection', connectionListener); } }