| Index: lib/matcher.js |
| =================================================================== |
| --- a/lib/matcher.js |
| +++ b/lib/matcher.js |
| @@ -243,17 +243,17 @@ |
| * rules into two Matcher instances. |
| * @constructor |
| * @augments Matcher |
| */ |
| function CombinedMatcher() |
| { |
| this.blacklist = new Matcher(); |
| this.whitelist = new Matcher(); |
| - this.resultCache = Object.create(null); |
| + this.resultCache = new Map(); |
| } |
| exports.CombinedMatcher = CombinedMatcher; |
| /** |
| * Maximal number of matching cache entries to be kept |
| * @type {number} |
| */ |
| CombinedMatcher.maxCacheEntries = 1000; |
| @@ -269,71 +269,56 @@ |
| /** |
| * Matcher for exception rules. |
| * @type {Matcher} |
| */ |
| whitelist: null, |
| /** |
| * Lookup table of previous matchesAny results |
| - * @type {Object} |
| + * @type {Map.<string,Filter>} |
| */ |
| resultCache: null, |
| /** |
| - * Number of entries in resultCache |
| - * @type {number} |
| - */ |
| - cacheEntries: 0, |
| - |
| - /** |
| * @see Matcher#clear |
| */ |
| clear() |
| { |
| this.blacklist.clear(); |
| this.whitelist.clear(); |
| - this.resultCache = Object.create(null); |
| - this.cacheEntries = 0; |
| + this.resultCache.clear(); |
| }, |
| /** |
| * @see Matcher#add |
| * @param {Filter} filter |
| */ |
| add(filter) |
| { |
| if (filter instanceof WhitelistFilter) |
| this.whitelist.add(filter); |
| else |
| this.blacklist.add(filter); |
| - if (this.cacheEntries > 0) |
| - { |
| - this.resultCache = Object.create(null); |
| - this.cacheEntries = 0; |
| - } |
| + this.resultCache.clear(); |
| }, |
| /** |
| * @see Matcher#remove |
| * @param {Filter} filter |
| */ |
| remove(filter) |
| { |
| if (filter instanceof WhitelistFilter) |
| this.whitelist.remove(filter); |
| else |
| this.blacklist.remove(filter); |
| - if (this.cacheEntries > 0) |
| - { |
| - this.resultCache = Object.create(null); |
| - this.cacheEntries = 0; |
| - } |
| + this.resultCache.clear(); |
| }, |
| /** |
| * @see Matcher#findKeyword |
| * @param {Filter} filter |
| * @return {string} keyword |
| */ |
| findKeyword(filter) |
| @@ -419,30 +404,28 @@ |
| /** |
| * @see Matcher#matchesAny |
| * @inheritdoc |
| */ |
| matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly) |
| { |
| let key = location + " " + typeMask + " " + docDomain + " " + thirdParty + |
| " " + sitekey + " " + specificOnly; |
| - if (key in this.resultCache) |
| - return this.resultCache[key]; |
| - let result = this.matchesAnyInternal(location, typeMask, docDomain, |
| - thirdParty, sitekey, specificOnly); |
| + let result = this.resultCache.get(key); |
| + if (typeof result != "undefined") |
| + return result; |
| - if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) |
| - { |
| - this.resultCache = Object.create(null); |
| - this.cacheEntries = 0; |
| - } |
| + result = this.matchesAnyInternal(location, typeMask, docDomain, |
| + thirdParty, sitekey, specificOnly); |
| - this.resultCache[key] = result; |
| - this.cacheEntries++; |
| + if (this.resultCache.size >= CombinedMatcher.maxCacheEntries) |
| + this.resultCache.clear(); |
| + |
| + this.resultCache.set(key, result); |
| return result; |
| } |
| }; |
| /** |
| * Shared CombinedMatcher instance that should usually be used. |
| * @type {CombinedMatcher} |