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: Created Sept. 21, 2017, 11:47 a.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..81d584767bb94bb3423e43f4a02e85a159d9f488 100644
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -32,9 +32,9 @@ let filterByKey = [];
/**
* Lookup table, keys of the filters by filter text
- * @type {Object}
+ * @type {Map.<string,string>}
sergei 2017/09/21 12:02:10 Pay attention that after switching from Object to
kzar 2017/09/22 10:50:15 Yea, it looks like we only used the Filter's text
Wladimir Palant 2017/09/25 10:59:31 Agreed, we should use Filter objects as keys here.
sergei 2017/09/25 13:41:23 Done. I have checked when the type of key here is
Wladimir Palant 2017/09/25 13:57:16 A change in memory usage would be unexpected, both
*/
-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.text))
return;
let key = filterByKey.push(filter) - 1;
- keyByFilter[filter.text] = key;
+ keyByFilter.set(filter.text, 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.text);
+ if (typeof key == "undefined")
return;
- let key = keyByFilter[filter.text];
delete filterByKey[key];
- delete keyByFilter[filter.text];
+ keyByFilter.delete(filter.text);
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