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)) |