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

Unified Diff: lib/elemHide.js

Issue 29551638: Issue 5735 - Use JS Map instead of Object for global keyByFilter in elemHide.js (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: use objects as keys Created Sept. 25, 2017, 1:39 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: lib/elemHide.js
diff --git a/lib/elemHide.js b/lib/elemHide.js
index e99bb8a7f269e4df2370fb95bd950031503540b4..c38a5cd142a5cd36b6432a351f30370df1cf5ed4 100644
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -31,10 +31,10 @@ const {FilterNotifier} = require("filterNotifier");
let filterByKey = [];
/**
- * Lookup table, keys of the filters by filter text
- * @type {Object}
+ * Lookup table, keys of the filters by filter
+ * @type {Map.<Filter,string>}
*/
-let keyByFilter = Object.create(null);
+let keyByFilter = new Map();
/**
* Nested lookup table, filter (or false if inactive) by filter key by domain.
@@ -91,7 +91,7 @@ let ElemHide = exports.ElemHide = {
clear()
{
filterByKey = [];
- keyByFilter = Object.create(null);
+ keyByFilter = new Map();
filtersByDomain = new Map();
filterKeyBySelector = Object.create(null);
unconditionalSelectors = unconditionalFilterKeys = null;
@@ -143,11 +143,11 @@ let ElemHide = exports.ElemHide = {
}
else
{
- if (filter.text in keyByFilter)
+ if (keyByFilter.has(filter))
return;
let key = filterByKey.push(filter) - 1;
- keyByFilter[filter.text] = key;
+ keyByFilter.set(filter, key);
if (!(filter.domains || filter.selector in exceptions))
{
@@ -204,12 +204,12 @@ let ElemHide = exports.ElemHide = {
}
else
{
- if (!(filter.text in keyByFilter))
+ let key = keyByFilter.get(filter);
+ if (typeof key == "undefined")
return;
- let key = keyByFilter[filter.text];
delete filterByKey[key];
- delete keyByFilter[filter.text];
+ keyByFilter.delete(filter);
this._removeFilterKey(key, filter);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld