Browse Source

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 <trev.norris@gmail.com>
archived-io.js-v0.10
cjihrig 11 years ago
committed by Trevor Norris
parent
commit
25702abc56
  1. 24
      lib/net.js

24
lib/net.js

@ -62,8 +62,8 @@ function isPipeName(s) {
} }
exports.createServer = function() { exports.createServer = function(options, connectionListener) {
return new Server(arguments[0], arguments[1]); return new Server(options, connectionListener);
}; };
@ -984,23 +984,23 @@ function afterConnect(status, handle, req, readable, writable) {
} }
function Server(/* [ options, ] listener */) { function Server(options, connectionListener) {
if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]); if (!(this instanceof Server))
return new Server(options, connectionListener);
events.EventEmitter.call(this); events.EventEmitter.call(this);
var self = this; var self = this;
var options; if (util.isFunction(options)) {
connectionListener = options;
if (util.isFunction(arguments[0])) {
options = {}; options = {};
self.on('connection', arguments[0]); self.on('connection', connectionListener);
} else { } else {
options = arguments[0] || {}; options = options || {};
if (util.isFunction(arguments[1])) { if (util.isFunction(connectionListener))
self.on('connection', arguments[1]); self.on('connection', connectionListener);
}
} }
this._connections = 0; this._connections = 0;

Loading…
Cancel
Save