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

Unified Diff: lib/matcher.js

Issue 30018555: Issue 7311 - Split _checkEntryMatchByDomain() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 26, 2019, 9:29 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/matcher.js
===================================================================
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -417,16 +417,62 @@
result = candidate;
resultCount = count;
resultLength = candidate.length;
}
}
return result;
}
+ _matchFilterWithoutDomain(filter, location, typeMask, thirdParty, sitekey,
+ collection)
+ {
+ if (filter.matchesWithoutDomain(location, typeMask, thirdParty, sitekey))
+ {
+ if (!collection)
+ return filter;
+
+ collection.push(filter);
+ }
+
+ return null;
+ }
+
+ _matchFiltersByDomain(filtersByDomain, location, typeMask, docDomain,
+ thirdParty, sitekey, specificOnly, collection)
+ {
+ let excluded = new Set();
+
+ for (let suffix of domainSuffixes(docDomain ?
+ normalizeHostname(docDomain) : "",
+ !specificOnly))
+ {
+ let filters = filtersByDomain.get(suffix);
+ if (filters)
+ {
+ for (let [filter, include] of filters.entries())
+ {
+ if (!include)
+ {
+ excluded.add(filter);
+ }
+ else if ((excluded.size == 0 || !excluded.has(filter)) &&
+ this._matchFilterWithoutDomain(filter, location, typeMask,
+ thirdParty, sitekey,
+ collection))
+ {
+ return filter;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
_checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty,
sitekey, specificOnly, collection)
{
let filters = this._simpleFiltersByKeyword.get(keyword);
if (filters)
{
let lowerCaseLocation = location.toLowerCase();
@@ -479,59 +525,28 @@
}
_checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty,
sitekey, specificOnly, collection)
{
let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword);
if (filtersByDomain)
{
- // Because of the memory optimization in the add function, most of the
- // time this will be a filter rather than a map.
- if (!(filtersByDomain instanceof Map))
+ if (filtersByDomain instanceof Map)
{
- if (filtersByDomain.matchesWithoutDomain(location, typeMask,
- thirdParty, sitekey))
- {
- if (!collection)
- return filtersByDomain;
-
- collection.push(filtersByDomain);
- }
-
- return null;
+ return this._matchFiltersByDomain(filtersByDomain, location, typeMask,
+ docDomain, thirdParty, sitekey,
+ specificOnly, collection);
}
- let excluded = new Set();
-
- for (let suffix of domainSuffixes(docDomain ?
- normalizeHostname(docDomain) : "",
- !specificOnly))
- {
- let filters = filtersByDomain.get(suffix);
- if (filters)
- {
- for (let [filter, include] of filters.entries())
- {
- if (!include)
- {
- excluded.add(filter);
- }
- else if ((excluded.size == 0 || !excluded.has(filter)) &&
- filter.matchesWithoutDomain(location, typeMask,
- thirdParty, sitekey))
- {
- if (!collection)
- return filter;
-
- collection.push(filter);
- }
- }
- }
- }
+ // Because of the memory optimization in the add function, most of the
+ // time this will be a filter rather than a map.
+ return this._matchFilterWithoutDomain(filtersByDomain, location,
+ typeMask, thirdParty, sitekey,
+ collection);
}
return null;
}
/**
* Checks whether the entries for a particular keyword match a URL
* @param {string} keyword
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld