Skip to content

Commit 56668f5

Browse files
committed
events: speed up .removeAllListeners()
1 parent b7fd55e commit 56668f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/events.js

+11
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ EventEmitter.prototype.removeListener = function(type, listener) {
239239
EventEmitter.prototype.removeAllListeners = function(type) {
240240
if (!this._events) return this;
241241

242+
// fast path
243+
if (!this._events.removeListener) {
244+
if (arguments.length === 0) {
245+
this._events = {};
246+
} else if (type && this._events && this._events[type]) {
247+
this._events[type] = null;
248+
}
249+
return this;
250+
}
251+
252+
// slow(ish) path, emit 'removeListener' events for all removals
242253
if (arguments.length === 0) {
243254
for (var key in this._events) {
244255
if (key === 'removeListener') continue;

0 commit comments

Comments
 (0)