diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-08-01 01:29:10 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-09-22 03:48:59 +0200 |
commit | 56668f54d11225b0bcdf93dc2fba846febdbb19f (patch) | |
tree | ff2e85e11602b77d304a3eb318f3e5ddf84667fd /lib/events.js | |
parent | b7fd55e9a0fe78d9c258039de51fc38f1ce5a74d (diff) | |
download | android-node-v8-56668f54d11225b0bcdf93dc2fba846febdbb19f.tar.gz android-node-v8-56668f54d11225b0bcdf93dc2fba846febdbb19f.tar.bz2 android-node-v8-56668f54d11225b0bcdf93dc2fba846febdbb19f.zip |
events: speed up .removeAllListeners()
Diffstat (limited to 'lib/events.js')
-rw-r--r-- | lib/events.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/events.js b/lib/events.js index 732f16872a..11f91b5ccb 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; |