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

Unified Diff: lib/filterClasses.js

Issue 29841555: Issue 6814 - Avoid redundant calls to domains getter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 29, 2018, 12:18 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/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -477,54 +477,58 @@
// upper-case to avoid false positives here. Instead we need to
// change the way filter options are parsed.
if (this.sitekeys &&
(!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0))
{
return false;
}
+ let {domains} = this;
+
// If no domains are set the rule matches everywhere
- if (!this.domains)
+ if (!domains)
return true;
// If the document has no host name, match only if the filter
// isn't restricted to specific domains
if (!docDomain)
- return this.domains.get("");
+ return domains.get("");
docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
while (true)
{
- let isDomainIncluded = this.domains.get(docDomain);
+ let isDomainIncluded = domains.get(docDomain);
if (typeof isDomainIncluded != "undefined")
return isDomainIncluded;
let nextDot = docDomain.indexOf(".");
if (nextDot < 0)
break;
docDomain = docDomain.substr(nextDot + 1);
}
- return this.domains.get("");
+ return domains.get("");
},
/**
* Checks whether this filter is active only on a domain and its subdomains.
* @param {string} docDomain
* @return {boolean}
*/
isActiveOnlyOnDomain(docDomain)
{
- if (!docDomain || !this.domains || this.domains.get(""))
+ let {domains} = this;
+
+ if (!docDomain || !domains || domains.get(""))
return false;
docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
- for (let [domain, isIncluded] of this.domains)
+ for (let [domain, isIncluded] of domains)
{
if (isIncluded && domain != docDomain)
{
if (domain.length <= docDomain.length)
return false;
if (!domain.endsWith("." + docDomain))
return false;
@@ -535,18 +539,20 @@
},
/**
* Checks whether this filter is generic or specific
* @return {boolean}
*/
isGeneric()
{
+ let {domains} = this;
+
return !(this.sitekeys && this.sitekeys.length) &&
- (!this.domains || this.domains.get(""));
+ (!domains || domains.get(""));
},
/**
* See Filter.serialize()
* @inheritdoc
*/
serialize(buffer)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld