net: use rest parameters instead of arguments
In v8 6.0, rest parameters are significantly faster than other ways to create an array of the arguments, even for small numbers. PR-URL: https://github.com/nodejs/node/pull/13472 Refs: https://github.com/nodejs/node/issues/13430 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
d98606f968
commit
472a66517a
22
lib/net.js
22
lib/net.js
@ -93,11 +93,7 @@ function createServer(options, connectionListener) {
|
|||||||
// connect(port, [host], [cb])
|
// connect(port, [host], [cb])
|
||||||
// connect(path, [cb]);
|
// connect(path, [cb]);
|
||||||
//
|
//
|
||||||
function connect() {
|
function connect(...args) {
|
||||||
var args = new Array(arguments.length);
|
|
||||||
for (var i = 0; i < arguments.length; i++)
|
|
||||||
args[i] = arguments[i];
|
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
|
||||||
var normalized = normalizeArgs(args);
|
var normalized = normalizeArgs(args);
|
||||||
var options = normalized[0];
|
var options = normalized[0];
|
||||||
debug('createConnection', normalized);
|
debug('createConnection', normalized);
|
||||||
@ -950,19 +946,15 @@ function internalConnect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Socket.prototype.connect = function() {
|
Socket.prototype.connect = function(...args) {
|
||||||
let normalized;
|
let normalized;
|
||||||
// If passed an array, it's treated as an array of arguments that have
|
// If passed an array, it's treated as an array of arguments that have
|
||||||
// already been normalized (so we don't normalize more than once). This has
|
// already been normalized (so we don't normalize more than once). This has
|
||||||
// been solved before in https://github.com/nodejs/node/pull/12342, but was
|
// been solved before in https://github.com/nodejs/node/pull/12342, but was
|
||||||
// reverted as it had unintended side effects.
|
// reverted as it had unintended side effects.
|
||||||
if (Array.isArray(arguments[0]) && arguments[0][normalizedArgsSymbol]) {
|
if (Array.isArray(args[0]) && args[0][normalizedArgsSymbol]) {
|
||||||
normalized = arguments[0];
|
normalized = args[0];
|
||||||
} else {
|
} else {
|
||||||
var args = new Array(arguments.length);
|
|
||||||
for (var i = 0; i < arguments.length; i++)
|
|
||||||
args[i] = arguments[i];
|
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
|
||||||
normalized = normalizeArgs(args);
|
normalized = normalizeArgs(args);
|
||||||
}
|
}
|
||||||
var options = normalized[0];
|
var options = normalized[0];
|
||||||
@ -1414,11 +1406,7 @@ function listenInCluster(server, address, port, addressType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Server.prototype.listen = function() {
|
Server.prototype.listen = function(...args) {
|
||||||
var args = new Array(arguments.length);
|
|
||||||
for (var i = 0; i < arguments.length; i++)
|
|
||||||
args[i] = arguments[i];
|
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
|
||||||
var normalized = normalizeArgs(args);
|
var normalized = normalizeArgs(args);
|
||||||
var options = normalized[0];
|
var options = normalized[0];
|
||||||
var cb = normalized[1];
|
var cb = normalized[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user