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
Next Next commit
net: don't create unnecessary closure
Pass arguments to fireErrorCallbacks() explicitly.  Saves allocation
an unnecessary closure context.

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 7b4830378311fd31f3b79d66d77fe4ebc95ed317
6 changes: 3 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Socket.prototype.destroySoon = function() {
Socket.prototype._destroy = function(exception, cb) {
debug('destroy');

function fireErrorCallbacks(self) {
function fireErrorCallbacks(self, exception, cb) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is done for performance, but does shadowing negate that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean shadowing of variable/argument names? No, should not be a factor here.

if (cb) cb(exception);
if (exception && !self._writableState.errorEmitted) {
process.nextTick(emitErrorNT, self, exception);
Expand All @@ -508,7 +508,7 @@ Socket.prototype._destroy = function(exception, cb) {

if (this.destroyed) {
debug('already destroyed, fire error callbacks');
fireErrorCallbacks(this);
fireErrorCallbacks(this, exception, cb);
return;
}

Expand Down Expand Up @@ -540,7 +540,7 @@ Socket.prototype._destroy = function(exception, cb) {
// to make it re-entrance safe in case Socket.prototype.destroy()
// is called within callbacks
this.destroyed = true;
fireErrorCallbacks(this);
fireErrorCallbacks(this, exception, cb);

if (this._server) {
COUNTER_NET_SERVER_CONNECTION_CLOSE(this);
Expand Down