diff options
author | Nathan Woltman <nwoltman@outlook.com> | 2015-12-20 02:01:34 -0500 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-10 18:45:08 -0800 |
commit | d0582ef9e19e8ed941b0a585c935ad11919080ee (patch) | |
tree | 867f8ef85cb0b7bafef37ee5bd96f7f4868baae1 /lib/net.js | |
parent | 0ea3899cabfebc764b8dedbd64d306b54db81fa6 (diff) | |
download | android-node-v8-d0582ef9e19e8ed941b0a585c935ad11919080ee.tar.gz android-node-v8-d0582ef9e19e8ed941b0a585c935ad11919080ee.tar.bz2 android-node-v8-d0582ef9e19e8ed941b0a585c935ad11919080ee.zip |
lib: copy arguments object instead of leaking it
Instead of leaking the arguments object by passing it as an
argument to a function, copy it's contents to a new array,
then pass the array. This allows V8 to optimize the function
that contains this code, improving performance.
PR-URL: https://github.com/nodejs/node/pull/4361
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js index f75c9b25b8..2442bcdee3 100644 --- a/lib/net.js +++ b/lib/net.js @@ -59,7 +59,11 @@ exports.createServer = function(options, connectionListener) { // connect(path, [cb]); // exports.connect = exports.createConnection = function() { - var args = normalizeConnectArgs(arguments); + const argsLen = arguments.length; + var args = new Array(argsLen); + for (var i = 0; i < argsLen; i++) + args[i] = arguments[i]; + args = normalizeConnectArgs(args); debug('createConnection', args); var s = new Socket(args[0]); return Socket.prototype.connect.apply(s, args); @@ -858,7 +862,11 @@ Socket.prototype.connect = function(options, cb) { // Old API: // connect(port, [host], [cb]) // connect(path, [cb]); - var args = normalizeConnectArgs(arguments); + const argsLen = arguments.length; + var args = new Array(argsLen); + for (var i = 0; i < argsLen; i++) + args[i] = arguments[i]; + args = normalizeConnectArgs(args); return Socket.prototype.connect.apply(this, args); } |