Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 * @see Matcher#add | 292 * @see Matcher#add |
293 * @param {Filter} filter | 293 * @param {Filter} filter |
294 */ | 294 */ |
295 add(filter) | 295 add(filter) |
296 { | 296 { |
297 if (filter instanceof WhitelistFilter) | 297 if (filter instanceof WhitelistFilter) |
298 this.whitelist.add(filter); | 298 this.whitelist.add(filter); |
299 else | 299 else |
300 this.blacklist.add(filter); | 300 this.blacklist.add(filter); |
301 | 301 |
302 this.resultCache.clear(); | 302 this.resultCache.clear(); |
Manish Jethani
2018/03/10 15:54:37
We don't have to check the size here because we're
sergei
2018/03/12 12:03:00
I'm pretty sure that now it's even faster, tough i
| |
303 }, | 303 }, |
304 | 304 |
305 /** | 305 /** |
306 * @see Matcher#remove | 306 * @see Matcher#remove |
307 * @param {Filter} filter | 307 * @param {Filter} filter |
308 */ | 308 */ |
309 remove(filter) | 309 remove(filter) |
310 { | 310 { |
311 if (filter instanceof WhitelistFilter) | 311 if (filter instanceof WhitelistFilter) |
312 this.whitelist.remove(filter); | 312 this.whitelist.remove(filter); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 /** | 404 /** |
405 * @see Matcher#matchesAny | 405 * @see Matcher#matchesAny |
406 * @inheritdoc | 406 * @inheritdoc |
407 */ | 407 */ |
408 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly) | 408 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly) |
409 { | 409 { |
410 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty + | 410 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty + |
411 " " + sitekey + " " + specificOnly; | 411 " " + sitekey + " " + specificOnly; |
412 | 412 |
413 let result = this.resultCache.get(key); | 413 let result = this.resultCache.get(key); |
414 if (result !== undefined) | 414 if (typeof result != "undefined") |
Manish Jethani
2018/03/10 15:54:37
Assumption: an entry will never have a value of un
sergei
2018/03/12 12:03:01
AFAIK our coding style says to rather use `typeof
Manish Jethani
2018/03/12 13:42:42
This is really not about coding style. The cache c
sergei
2018/03/12 17:48:31
Please take a look around in this file, whenever o
Manish Jethani
2018/03/12 18:59:21
Done.
sergei
2018/03/13 13:56:41
I still think we should discuss whether we use typ
Manish Jethani
2018/03/13 14:32:49
Yes, let's have that discussion.
| |
415 return result; | 415 return result; |
416 | 416 |
417 result = this.matchesAnyInternal(location, typeMask, docDomain, | 417 result = this.matchesAnyInternal(location, typeMask, docDomain, |
418 thirdParty, sitekey, specificOnly); | 418 thirdParty, sitekey, specificOnly); |
419 | 419 |
420 if (this.resultCache.size >= CombinedMatcher.maxCacheEntries) | 420 if (this.resultCache.size >= CombinedMatcher.maxCacheEntries) |
Manish Jethani
2018/03/10 15:54:37
Again, we don't have to create a new object every
| |
421 this.resultCache.clear(); | 421 this.resultCache.clear(); |
422 | 422 |
423 this.resultCache.set(key, result); | 423 this.resultCache.set(key, result); |
424 | 424 |
425 return result; | 425 return result; |
426 } | 426 } |
427 }; | 427 }; |
428 | 428 |
429 /** | 429 /** |
430 * Shared CombinedMatcher instance that should usually be used. | 430 * Shared CombinedMatcher instance that should usually be used. |
431 * @type {CombinedMatcher} | 431 * @type {CombinedMatcher} |
432 */ | 432 */ |
433 exports.defaultMatcher = new CombinedMatcher(); | 433 exports.defaultMatcher = new CombinedMatcher(); |
LEFT | RIGHT |