Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/common.js

Issue 29410614: Noissue - Make _listeners a Set object (Closed)
Patch Set: Created April 12, 2017, 12:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld