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

Unified Diff: lib/filterClasses.js

Issue 29550662: Issue 5735 - Use JS Map instead of Object for property domains of Filter objects (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: Created Sept. 20, 2017, 12:59 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
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
diff --git a/lib/filterClasses.js b/lib/filterClasses.js
index 417e4d8df3cc13fdd4daa0d6ac14489ad73b92cb..ec7d3d7067494ce7d630844ed57edd194b4641f9 100644
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -359,7 +359,7 @@ ActiveFilter.prototype = extend(Filter, {
/**
* Map containing domains that this filter should match on/not match
* on or null if the filter should match on all domains
- * @type {Object}
+ * @type {?Map.<string,boolean>}
*/
get domains()
{
@@ -383,11 +383,11 @@ ActiveFilter.prototype = extend(Filter, {
if (list.length == 1 && list[0][0] != "~")
{
// Fast track for the common one-domain scenario
- domains = Object.create(null);
- domains[""] = false;
+ domains = new Map();
+ domains.set("", false);
if (this.ignoreTrailingDot)
list[0] = list[0].replace(/\.+$/, "");
- domains[list[0]] = true;
+ domains.set(list[0], true);
Wladimir Palant 2017/09/21 08:11:44 You can initialize the Map object immediately: new
sergei 2017/09/21 10:50:34 Done. BTW, I would like to pay attention to the im
Wladimir Palant 2017/09/21 10:53:01 Feel free to measure that. I assume that the JS en
}
else
{
@@ -413,12 +413,12 @@ ActiveFilter.prototype = extend(Filter, {
}
if (!domains)
- domains = Object.create(null);
+ domains = new Map();
- domains[domain] = include;
+ domains.set(domain, include);
}
if (domains)
- domains[""] = !hasIncludes;
+ domains.set("", !hasIncludes);
}
this.domainSource = null;
@@ -458,7 +458,7 @@ ActiveFilter.prototype = extend(Filter, {
// If the document has no host name, match only if the filter
// isn't restricted to specific domains
if (!docDomain)
- return this.domains[""];
+ return this.domains.get("");
if (this.ignoreTrailingDot)
docDomain = docDomain.replace(/\.+$/, "");
@@ -466,15 +466,16 @@ ActiveFilter.prototype = extend(Filter, {
while (true)
{
- if (docDomain in this.domains)
- return this.domains[docDomain];
+ let isDomainIncluded = this.domains.get(docDomain);
+ if (isDomainIncluded != undefined)
Wladimir Palant 2017/09/21 08:11:44 We usually use the typeof operator: `typeof isDoma
sergei 2017/09/21 10:50:34 Acknowledged.
+ return isDomainIncluded;
let nextDot = docDomain.indexOf(".");
if (nextDot < 0)
break;
docDomain = docDomain.substr(nextDot + 1);
}
- return this.domains[""];
+ return this.domains.get("");
},
/**
@@ -484,16 +485,16 @@ ActiveFilter.prototype = extend(Filter, {
*/
isActiveOnlyOnDomain(docDomain)
{
- if (!docDomain || !this.domains || this.domains[""])
+ if (!docDomain || !this.domains || this.domains.get(""))
return false;
if (this.ignoreTrailingDot)
docDomain = docDomain.replace(/\.+$/, "");
docDomain = docDomain.toUpperCase();
- for (let domain in this.domains)
+ for (let [domain, isIncluded] of this.domains)
{
- if (this.domains[domain] && domain != docDomain)
+ if (isIncluded && domain != docDomain)
{
if (domain.length <= docDomain.length)
return false;
@@ -513,7 +514,7 @@ ActiveFilter.prototype = extend(Filter, {
isGeneric()
{
return !(this.sitekeys && this.sitekeys.length) &&
- (!this.domains || this.domains[""]);
+ (!this.domains || this.domains.get(""));
},
/**
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld