Skip to content

Commit 42451fc

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 0766ebe commit 42451fc

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

‎lib/net.js‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,26 +836,20 @@ function internalConnect(
836836
varerr;
837837

838838
if(localAddress||localPort){
839-
varbind;
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
}elseif(addressType===6){
845846
localAddress=localAddress||'::';
846-
bind=self._handle.bind6;
847+
err=self._handle.bind6(localAddress,localPort);
847848
}else{
848849
self._destroy(newTypeError('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
constex=exceptionWithHostPort(err,'bind',localAddress,localPort);
861855
self._destroy(ex);

0 commit comments

Comments
(0)