Skip to content

Commit c4fc0fe

Browse files
tricknotesbnoordhuis
authored andcommitted
https: optimize https.createConnection()
Stop using `arguments` for performance and readability.
1 parent a329729 commit c4fc0fe

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/https.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,25 @@ exports.createServer = function(opts, requestListener) {
5757

5858
// HTTPS agents.
5959

60-
function createConnection(/* [port, host, options] */) {
61-
var options = {};
62-
63-
if (typeof arguments[0] === 'object') {
64-
options = arguments[0];
65-
} else if (typeof arguments[1] === 'object') {
66-
options = arguments[1];
67-
options.port = arguments[0];
68-
} else if (typeof arguments[2] === 'object') {
69-
options = arguments[2];
70-
options.port = arguments[0];
71-
options.host = arguments[1];
60+
function createConnection(port, host, options) {
61+
if (typeof port === 'object') {
62+
options = port;
63+
} else if (typeof host === 'object') {
64+
options = host;
65+
} else if (typeof options === 'object') {
66+
options = options;
7267
} else {
73-
if (typeof arguments[0] === 'number') {
74-
options.port = arguments[0];
75-
}
76-
if (typeof arguments[1] === 'string') {
77-
options.host = arguments[1];
78-
}
68+
options = {};
69+
}
70+
71+
if (typeof port === 'number') {
72+
options.port = port;
7973
}
74+
75+
if (typeof host === 'string') {
76+
options.host = host;
77+
}
78+
8079
return tls.connect(options);
8180
}
8281

0 commit comments

Comments
 (0)