Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <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
bnoordhuis committed Apr 18, 2017
commit 117b83c2ddca0c9cd1834889bf322167900a3e53
14 changes: 4 additions & 10 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down