From dcc9e1a7d451fbafc73f4fba93a1a094e5690f6a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 11 Apr 2017 16:40:16 +0200 Subject: [PATCH] net: don't create unnecessary closure Don't call `Function#bind()` when a direct method call works just as well and is much cheaper. 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 | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/net.js b/lib/net.js index 65d57b2b89545b..0b8284fbdea1b8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -836,26 +836,20 @@ function internalConnect( var err; if (localAddress || localPort) { - var bind; + debug('binding to localAddress: %s and localPort: %d (addressType: %d)', + localAddress, localPort, addressType); if (addressType === 4) { localAddress = localAddress || '0.0.0.0'; - bind = self._handle.bind; + err = self._handle.bind(localAddress, localPort); } else if (addressType === 6) { localAddress = localAddress || '::'; - bind = self._handle.bind6; + err = self._handle.bind6(localAddress, localPort); } else { self._destroy(new TypeError('Invalid addressType: ' + addressType)); return; } - debug('binding to localAddress: %s and localPort: %d', - localAddress, - localPort); - - bind = bind.bind(self._handle); - err = bind(localAddress, localPort); - if (err) { const ex = exceptionWithHostPort(err, 'bind', localAddress, localPort); self._destroy(ex);