events: speed up .removeAllListeners()
This commit is contained in:
parent
b7fd55e9a0
commit
56668f54d1
@ -239,6 +239,17 @@ EventEmitter.prototype.removeListener = function(type, listener) {
|
|||||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||||
if (!this._events) return this;
|
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) {
|
if (arguments.length === 0) {
|
||||||
for (var key in this._events) {
|
for (var key in this._events) {
|
||||||
if (key === 'removeListener') continue;
|
if (key === 'removeListener') continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user