Skip to content

Commit cca8de6

Browse files
committed
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> Conflicts: lib/net.js
1 parent 4ca7cca commit cca8de6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/net.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function isPipeName(s) {
4848
return typeof s === 'string' && toNumber(s) === false;
4949
}
5050

51-
exports.createServer = function() {
52-
return new Server(arguments[0], arguments[1]);
51+
exports.createServer = function(options, connectionListener) {
52+
return new Server(options, connectionListener);
5353
};
5454

5555

@@ -991,22 +991,24 @@ function afterConnect(status, handle, req, readable, writable) {
991991
}
992992

993993

994-
function Server(/* [ options, ] listener */) {
995-
if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]);
994+
function Server(options, connectionListener) {
995+
if (!(this instanceof Server))
996+
return new Server(options, connectionListener);
997+
996998
events.EventEmitter.call(this);
997999

9981000
var self = this;
999-
10001001
var options;
10011002

1002-
if (typeof arguments[0] === 'function') {
1003+
if (typeof options === 'function') {
1004+
connectionListener = options;
10031005
options = {};
1004-
self.on('connection', arguments[0]);
1006+
self.on('connection', connectionListener);
10051007
} else {
1006-
options = arguments[0] || {};
1008+
options = options || {};
10071009

1008-
if (typeof arguments[1] === 'function') {
1009-
self.on('connection', arguments[1]);
1010+
if (typeof connectionListener === 'function') {
1011+
self.on('connection', connectionListener);
10101012
}
10111013
}
10121014

0 commit comments

Comments
 (0)