diff --git a/lib/events.js b/lib/events.js index 732f16872aa..11f91b5ccbd 100644 --- a/lib/events.js +++ b/lib/events.js @@ -239,6 +239,17 @@ EventEmitter.prototype.removeListener = function(type, listener) { EventEmitter.prototype.removeAllListeners = function(type) { if (!this._events) return this; + // fast path + if (!this._events.removeListener) { + if (arguments.length === 0) { + this._events = {}; + } else if (type && this._events && this._events[type]) { + this._events[type] = null; + } + return this; + } + + // slow(ish) path, emit 'removeListener' events for all removals if (arguments.length === 0) { for (var key in this._events) { if (key === 'removeListener') continue;