Skip to content

Commit dcc9e1a

Browse files
bnoordhuisevanlucas
authored andcommitted
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: #12342 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e09202b commit dcc9e1a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

lib/net.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -836,26 +836,20 @@ function internalConnect(
836836
var err;
837837

838838
if (localAddress || localPort) {
839-
var bind;
839+
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
840+
localAddress, localPort, addressType);
840841

841842
if (addressType === 4) {
842843
localAddress = localAddress || '0.0.0.0';
843-
bind = self._handle.bind;
844+
err = self._handle.bind(localAddress, localPort);
844845
} else if (addressType === 6) {
845846
localAddress = localAddress || '::';
846-
bind = self._handle.bind6;
847+
err = self._handle.bind6(localAddress, localPort);
847848
} else {
848849
self._destroy(new TypeError('Invalid addressType: ' + addressType));
849850
return;
850851
}
851852

852-
debug('binding to localAddress: %s and localPort: %d',
853-
localAddress,
854-
localPort);
855-
856-
bind = bind.bind(self._handle);
857-
err = bind(localAddress, localPort);
858-
859853
if (err) {
860854
const ex = exceptionWithHostPort(err, 'bind', localAddress, localPort);
861855
self._destroy(ex);

0 commit comments

Comments
 (0)