-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
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 <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>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Author
Member
|
||
|
||
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); | ||
|
@bnoordhuis I don't think it's safe to move the
debug()
here sincelocalAddress
is possibly assigned a different value below...