mirror of
https://github.com/nodejs/node.git
synced 2025-05-20 22:43:26 +00:00
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) {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user