Index: ext/common.js |
diff --git a/ext/common.js b/ext/common.js |
index 173bbaf443e1fc9eb0b5736e403e35a79c4755d7..1d66b1ed163c0af4bf585dd10c7b9a8d4f52362c 100644 |
--- a/ext/common.js |
+++ b/ext/common.js |
@@ -23,24 +23,21 @@ |
let EventTarget = ext._EventTarget = function() |
{ |
- this._listeners = []; |
+ this._listeners = new Set(); |
}; |
EventTarget.prototype = { |
addListener(listener) |
{ |
- if (this._listeners.indexOf(listener) == -1) |
- this._listeners.push(listener); |
+ this._listeners.add(listener); |
}, |
removeListener(listener) |
{ |
- let idx = this._listeners.indexOf(listener); |
- if (idx != -1) |
- this._listeners.splice(idx, 1); |
+ this._listeners.delete(listener); |
}, |
_dispatch(...args) |
{ |
let results = []; |
- let listeners = this._listeners.slice(); |
+ let listeners = [...this._listeners]; |
Sebastian Noack
2017/04/12 12:32:14
Is turning the set into an array even necessary, c
Manish Jethani
2017/04/12 12:37:50
Yeah, I'm trying to be compatible with the current
Sebastian Noack
2017/04/12 12:42:36
I see. This might have been the reason why the lis
Wladimir Palant
2017/04/12 14:43:02
It is. However, is that an efficient way of copyin
Sebastian Noack
2017/04/12 14:49:30
We don't need a set, an array is sufficient. So if
|
for (let listener of listeners) |
results.push(listener(...args)); |