Browse Source

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 <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
v7.x
Ben Noordhuis 8 years ago
committed by Evan Lucas
parent
commit
dcc9e1a7d4
  1. 14
      lib/net.js

14
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);

Loading…
Cancel
Save