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>
This commit is contained in:
parent
7b48303783
commit
117b83c2dd
14
lib/net.js
14
lib/net.js
@ -858,26 +858,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…
x
Reference in New Issue
Block a user