Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
net: remove use of arguments in Server constructor
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and trevnorris committed Oct 1, 2014
1 parent 7c04197 commit 25702ab
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function isPipeName(s) {
}


exports.createServer = function() {
return new Server(arguments[0], arguments[1]);
exports.createServer = function(options, connectionListener) {
return new Server(options, connectionListener);
};


Expand Down Expand Up @@ -984,23 +984,23 @@ 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 (util.isFunction(arguments[0])) {
if (util.isFunction(options)) {
connectionListener = options;
options = {};
self.on('connection', arguments[0]);
self.on('connection', connectionListener);
} else {
options = arguments[0] || {};
options = options || {};

if (util.isFunction(arguments[1])) {
self.on('connection', arguments[1]);
}
if (util.isFunction(connectionListener))
self.on('connection', connectionListener);
}

this._connections = 0;
Expand Down

0 comments on commit 25702ab

Please sign in to comment.