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

Unified Diff: lib/matcher.js

Issue 29965589: Issue 7181 - Keep a keyword-by-filter map after all (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Dec. 19, 2018, 6:24 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 | test/matcher.js » ('j') | 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
@@ -146,16 +146,23 @@
/**
* Blacklist/whitelist filter matching
*/
class Matcher
{
constructor()
{
/**
+ * Lookup table for keywords by their associated filter
+ * @type {Map.<RegExpFilter,string>}
+ * @private
+ */
+ this._keywordsByFilter = new Map();
+
+ /**
* Lookup table for simple filters by their associated keyword
* @type {Map.<string,(RegExpFilter|Set.<RegExpFilter>)>}
* @private
*/
this._simpleFiltersByKeyword = new Map();
/**
* Lookup table for complex filters by their associated keyword
@@ -184,24 +191,29 @@
}
/**
* Adds a filter to the matcher
* @param {RegExpFilter} filter
*/
add(filter)
{
+ if (this._keywordsByFilter.has(filter))
+ return;
+
// Look for a suitable keyword
let keyword = this.findKeyword(filter);
let locationOnly = filter.isLocationOnly();
addFilterByKeyword(filter, keyword,
locationOnly ? this._simpleFiltersByKeyword :
this._complexFiltersByKeyword);
+ this._keywordsByFilter.set(filter, keyword);
+
if (locationOnly)
return;
for (let type of nonDefaultTypes(filter.contentType))
{
let map = this._filterMapsByType.get(type);
if (!map)
this._filterMapsByType.set(type, map = new Map());
@@ -211,23 +223,28 @@
}
/**
* Removes a filter from the matcher
* @param {RegExpFilter} filter
*/
remove(filter)
{
- let keyword = this.findKeyword(filter);
+ let keyword = this._keywordsByFilter.get(filter);
+ if (typeof keyword == "undefined")
+ return;
+
let locationOnly = filter.isLocationOnly();
removeFilterByKeyword(filter, keyword,
locationOnly ? this._simpleFiltersByKeyword :
this._complexFiltersByKeyword);
+ this._keywordsByFilter.delete(filter);
+
if (locationOnly)
return;
for (let type of nonDefaultTypes(filter.contentType))
{
let map = this._filterMapsByType.get(type);
if (map)
removeFilterByKeyword(filter, keyword, map);
« no previous file with comments | « no previous file | test/matcher.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld