Browse Source

net: don't create unnecessary closure

Pass arguments to fireErrorCallbacks() explicitly.  Saves allocation
an unnecessary closure context.

PR-URL: https://github.com/nodejs/node/pull/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>
v6
Ben Noordhuis 8 years ago
parent
commit
7b48303783
  1. 6
      lib/net.js

6
lib/net.js

@ -498,7 +498,7 @@ Socket.prototype.destroySoon = function() {
Socket.prototype._destroy = function(exception, cb) { Socket.prototype._destroy = function(exception, cb) {
debug('destroy'); debug('destroy');
function fireErrorCallbacks(self) { function fireErrorCallbacks(self, exception, cb) {
if (cb) cb(exception); if (cb) cb(exception);
if (exception && !self._writableState.errorEmitted) { if (exception && !self._writableState.errorEmitted) {
process.nextTick(emitErrorNT, self, exception); process.nextTick(emitErrorNT, self, exception);
@ -508,7 +508,7 @@ Socket.prototype._destroy = function(exception, cb) {
if (this.destroyed) { if (this.destroyed) {
debug('already destroyed, fire error callbacks'); debug('already destroyed, fire error callbacks');
fireErrorCallbacks(this); fireErrorCallbacks(this, exception, cb);
return; return;
} }
@ -540,7 +540,7 @@ Socket.prototype._destroy = function(exception, cb) {
// to make it re-entrance safe in case Socket.prototype.destroy() // to make it re-entrance safe in case Socket.prototype.destroy()
// is called within callbacks // is called within callbacks
this.destroyed = true; this.destroyed = true;
fireErrorCallbacks(this); fireErrorCallbacks(this, exception, cb);
if (this._server) { if (this._server) {
COUNTER_NET_SERVER_CONNECTION_CLOSE(this); COUNTER_NET_SERVER_CONNECTION_CLOSE(this);

Loading…
Cancel
Save