From 0000d71dc607a6e1a620542e91ea00e385f3efca Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 13 Feb 2017 13:26:42 -0800 Subject: [PATCH] tls: avoid potentially deoptimizing use of arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace use of arguments with `...args` ``` tls/tls-connect.js dur=5 concurrency=1 -9.43 % 0.172136744 tls/tls-connect.js dur=5 concurrency=10 29.05 % ** 0.001108115 ``` PR-URL: https://github.com/nodejs/node/pull/11357 Reviewed-By: Sam Roberts Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- lib/_tls_wrap.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 83a0f109939dc5..b2d30fb25ae6bf 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -294,9 +294,9 @@ var proxiedMethods = [ // Proxy HandleWrap, PipeWrap and TCPWrap methods proxiedMethods.forEach(function(name) { - tls_wrap.TLSWrap.prototype[name] = function methodProxy() { + tls_wrap.TLSWrap.prototype[name] = function methodProxy(...args) { if (this._parent[name]) - return this._parent[name].apply(this._parent, arguments); + return this._parent[name].apply(this._parent, args); }; }); @@ -986,11 +986,7 @@ function normalizeConnectArgs(listArgs) { return (cb) ? [options, cb] : [options]; } -exports.connect = function(/* [port,] [host,] [options,] [cb] */) { - const argsLen = arguments.length; - var args = new Array(argsLen); - for (var i = 0; i < argsLen; i++) - args[i] = arguments[i]; +exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) { args = normalizeConnectArgs(args); var options = args[0]; var cb = args[1];