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

Unified Diff: lib/matcher.js

Issue 29907586: Issue 6994 - Use shortcut matching for location only filters (Closed)
Patch Set: Address PS1 Comments Created Oct. 20, 2018, 11:07 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/filterClasses.js ('K') | « lib/filterClasses.js ('k') | 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
@@ -55,35 +55,55 @@
{
constructor()
{
/**
* Lookup table for filters by their associated keyword
* @type {Map.<string,(Filter|Set.<Filter>)>}
*/
this.filterByKeyword = new Map();
+
+ /**
+ * Lookup table for location only filters by their associated keyword
+ * for shortcut matching.
+ * @type {Map.<string,(Filter|Set.<Filter>)>}
+ */
+ this.locationFiltersByKeyword = new Map();
}
/**
* Removes all known filters
*/
clear()
{
this.filterByKeyword.clear();
+ this.locationFiltersByKeyword.clear();
}
/**
* Adds a filter to the matcher
* @param {RegExpFilter} filter
*/
add(filter)
{
// Look for a suitable keyword
let keyword = this.findKeyword(filter);
let set = this.filterByKeyword.get(keyword);
+
+ if (filter.isLocationOnly)
+ {
+ let locationSet = this.locationFiltersByKeyword.get(keyword);
+ if (typeof locationSet == "undefined")
+ this.locationFiltersByKeyword.set(keyword, new Set([filter]));
+ else
+ {
+ locationSet.add(filter);
+ }
+ }
+
if (typeof set == "undefined")
{
this.filterByKeyword.set(keyword, filter);
}
else if (set.size == 1)
{
if (filter != set)
this.filterByKeyword.set(keyword, new Set([set, filter]));
@@ -163,16 +183,27 @@
* @param {boolean} [thirdParty]
* @param {string} [sitekey]
* @param {boolean} [specificOnly]
* @returns {?Filter}
*/
_checkEntryMatch(keyword, location, typeMask, docDomain, thirdParty, sitekey,
specificOnly)
{
+ let locationFilters = this.locationFiltersByKeyword.get(keyword);
+ if (typeof locationFilters != "undefined")
+ {
+ for (let filter of locationFilters)
+ {
+ if (filter.contentType == 0 && typeMask == 0)
+ continue;
Jon Sonesen 2018/10/20 23:09:48 I think this should be in both iterations?
+ if (filter.matchesLocation(location))
+ return filter;
+ }
+ }
let set = this.filterByKeyword.get(keyword);
if (typeof set == "undefined")
return null;
for (let filter of set)
{
if (specificOnly && filter.isGeneric() &&
!(filter instanceof WhitelistFilter))
« lib/filterClasses.js ('K') | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld