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

Unified Diff: lib/elemHide.js

Issue 29764555: Noissue - Use two sets for excluded and included filters by domain (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created April 28, 2018, 4:15 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
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -22,17 +22,17 @@
*/
const {ElemHideException} = require("./filterClasses");
const {FilterNotifier} = require("./filterNotifier");
/**
* Lookup table, active flag, by filter by domain.
* (Only contains filters that aren't unconditionally matched for all domains.)
- * @type {Map.<string,Map.<Filter,boolean>>}
+ * @type {Map.<string,Array.<Set.<Filter>>>}
*/
let filtersByDomain = new Map();
/**
* Lookup table, filter by selector. (Only used for selectors that are
* unconditionally matched for all domains.)
* @type {Map.<string,Filter>}
*/
@@ -83,18 +83,23 @@
_addToFiltersByDomain(filter)
{
let domains = filter.domains || defaultDomains;
for (let [domain, isIncluded] of domains)
{
let filters = filtersByDomain.get(domain);
if (!filters)
- filtersByDomain.set(domain, filters = new Map());
- filters.set(filter, isIncluded);
+ filtersByDomain.set(domain, filters = []);
+
+ let setIndex = +isIncluded;
Manish Jethani 2018/04/28 16:35:35 Conveniently boolean converted to number gives us
+ if (!filters[setIndex])
Manish Jethani 2018/04/28 16:35:35 The number of entries is the same as before. If th
+ filters[setIndex] = new Set();
+
+ filters[setIndex].add(filter);
}
},
/**
* Add a new element hiding filter
* @param {ElemHideFilter} filter
*/
add(filter)
@@ -162,19 +167,21 @@
unconditionalSelectors = null;
}
// Conditionally applied element hiding filters
else
{
let domains = filter.domains || defaultDomains;
for (let domain of domains.keys())
{
- let filters = filtersByDomain.get(domain);
- if (filters)
- filters.delete(filter);
+ for (let set of filtersByDomain.get(domain) || [])
+ {
+ if (set)
+ set.delete(filter);
+ }
}
}
knownFilters.delete(filter);
FilterNotifier.emit("elemhideupdate");
},
/**
@@ -243,35 +250,40 @@
let selectors = [];
if (typeof criteria == "undefined")
criteria = ElemHide.ALL_MATCHING;
if (criteria < ElemHide.NO_UNCONDITIONAL)
selectors = this.getUnconditionalSelectors();
let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
- let seenFilters = new Set();
+ let seenFilters = [];
Manish Jethani 2018/04/28 16:35:35 This is now an array of sets. The maximum number o
let currentDomain = domain ? domain.toUpperCase() : "";
while (true)
{
if (specificOnly && currentDomain == "")
break;
- let filters = filtersByDomain.get(currentDomain);
- if (filters)
+ let [excluded, included] = filtersByDomain.get(currentDomain) || [];
+ if (excluded)
+ seenFilters.push(excluded);
+
+ for (let filter of included || [])
{
- for (let [filter, isIncluded] of filters)
+ for (let set of seenFilters)
Manish Jethani 2018/04/28 18:47:06 By the way, in case it isn't clear, the reason thi
{
Manish Jethani 2018/04/28 18:47:06 Note that as a side effect of this change a filter
- if (seenFilters.has(filter))
- continue;
- seenFilters.add(filter);
+ if (set.has(filter))
+ {
+ filter = null;
+ break;
+ }
+ }
- if (isIncluded && !this.getException(filter, domain))
- selectors.push(filter.selector);
- }
+ if (filter && !this.getException(filter, domain))
+ selectors.push(filter.selector);
}
if (currentDomain == "")
break;
let nextDot = currentDomain.indexOf(".");
currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld