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

Commit 25702ab

Browse files
cjihrigtrevnorris
authored andcommitted
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 <[email protected]>
1 parent 7c04197 commit 25702ab

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/net.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function isPipeName(s) {
6262
}
6363

6464

65-
exports.createServer = function() {
66-
return new Server(arguments[0], arguments[1]);
65+
exports.createServer = function(options, connectionListener) {
66+
return new Server(options, connectionListener);
6767
};
6868

6969

@@ -984,23 +984,23 @@ function afterConnect(status, handle, req, readable, writable) {
984984
}
985985

986986

987-
function Server(/* [ options, ] listener */) {
988-
if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]);
987+
function Server(options, connectionListener) {
988+
if (!(this instanceof Server))
989+
return new Server(options, connectionListener);
990+
989991
events.EventEmitter.call(this);
990992

991993
var self = this;
992994

993-
var options;
994-
995-
if (util.isFunction(arguments[0])) {
995+
if (util.isFunction(options)) {
996+
connectionListener = options;
996997
options = {};
997-
self.on('connection', arguments[0]);
998+
self.on('connection', connectionListener);
998999
} else {
999-
options = arguments[0] || {};
1000+
options = options || {};
10001001

1001-
if (util.isFunction(arguments[1])) {
1002-
self.on('connection', arguments[1]);
1003-
}
1002+
if (util.isFunction(connectionListener))
1003+
self.on('connection', connectionListener);
10041004
}
10051005

10061006
this._connections = 0;

0 commit comments

Comments
 (0)