From 94385c6d70fb5669d6f095ab3ff419464bc2cc40 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 11 Apr 2017 18:05:48 +0200 Subject: [PATCH] net: don't normalize twice in Socket#connect() Split up Socket#connect() so that we don't call normalizeArgs() twice when invoking net.connect() or net.createConnection(). PR-URL: https://github.com/nodejs/node/pull/12342 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- lib/net.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index a9bb212120e326..83ab9646db23ef 100644 --- a/lib/net.js +++ b/lib/net.js @@ -73,7 +73,7 @@ function connect() { socket.setTimeout(options.timeout); } - return Socket.prototype.connect.call(socket, options, cb); + return realConnect.call(socket, options, cb); } @@ -899,7 +899,11 @@ Socket.prototype.connect = function() { const normalized = normalizeArgs(args); const options = normalized[0]; const cb = normalized[1]; + return realConnect.call(this, options, cb); +}; + +function realConnect(options, cb) { if (this.write !== Socket.prototype.write) this.write = Socket.prototype.write; @@ -940,7 +944,7 @@ Socket.prototype.connect = function() { lookupAndConnect(this, options); } return this; -}; +} function lookupAndConnect(self, options) {