OLD | NEW |
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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 if (value != this._lastHit) | 427 if (value != this._lastHit) |
428 { | 428 { |
429 let oldValue = this._lastHit; | 429 let oldValue = this._lastHit; |
430 this._lastHit = value; | 430 this._lastHit = value; |
431 filterNotifier.emit("filter.lastHit", this, value, oldValue); | 431 filterNotifier.emit("filter.lastHit", this, value, oldValue); |
432 } | 432 } |
433 return this._lastHit; | 433 return this._lastHit; |
434 }, | 434 }, |
435 | 435 |
436 /** | 436 /** |
| 437 * Internal counter to keep track of the number of times the |
| 438 * {@link ActiveFilter#domains} property is accessed. |
| 439 * @type {number} |
| 440 * @private |
| 441 */ |
| 442 _domainsAccessCount: 0, |
| 443 |
| 444 /** |
437 * String that the domains property should be generated from | 445 * String that the domains property should be generated from |
438 * @type {?string} | 446 * @type {?string} |
439 */ | 447 */ |
440 domainSource: null, | 448 domainSource: null, |
441 | 449 |
442 /** | 450 /** |
443 * Separator character used in domainSource property, must be | 451 * Separator character used in domainSource property, must be |
444 * overridden by subclasses | 452 * overridden by subclasses |
445 * @type {string} | 453 * @type {string} |
446 */ | 454 */ |
447 domainSeparator: null, | 455 domainSeparator: null, |
448 | 456 |
449 /** | 457 /** |
450 * Map containing domains that this filter should match on/not match | 458 * Map containing domains that this filter should match on/not match |
451 * on or null if the filter should match on all domains | 459 * on or null if the filter should match on all domains |
452 * @type {?Map.<string,boolean>} | 460 * @type {?Map.<string,boolean>} |
453 */ | 461 */ |
454 get domains() | 462 get domains() |
455 { | 463 { |
| 464 // For some filter types this property is accessed only rarely, especially |
| 465 // when the subscriptions are initially loaded. We defer any caching for |
| 466 // such filters. |
| 467 let cacheValue = ++this._domainsAccessCount > 3; |
| 468 |
456 let domains = null; | 469 let domains = null; |
457 | 470 |
458 if (this.domainSource) | 471 if (this.domainSource) |
459 { | 472 { |
460 let source = this.domainSource.toLowerCase(); | 473 let source = this.domainSource.toLowerCase(); |
461 | 474 |
462 let knownMap = knownDomainMaps.get(source); | 475 let knownMap = knownDomainMaps.get(source); |
463 if (knownMap) | 476 if (knownMap) |
464 { | 477 { |
465 domains = knownMap; | 478 domains = knownMap; |
(...skipping 30 matching lines...) Expand all Loading... |
496 if (!domains) | 509 if (!domains) |
497 domains = new Map(); | 510 domains = new Map(); |
498 | 511 |
499 domains.set(domain, include); | 512 domains.set(domain, include); |
500 } | 513 } |
501 | 514 |
502 if (domains) | 515 if (domains) |
503 domains.set("", !hasIncludes); | 516 domains.set("", !hasIncludes); |
504 } | 517 } |
505 | 518 |
506 if (domains) | 519 if (!domains || cacheValue) |
507 knownDomainMaps.set(source, domains); | 520 knownDomainMaps.set(source, domains); |
508 } | 521 } |
509 | 522 |
510 this.domainSource = null; | 523 if (!domains || cacheValue) |
| 524 this.domainSource = null; |
511 } | 525 } |
512 | 526 |
513 Object.defineProperty(this, "domains", {value: domains}); | 527 if (!domains || cacheValue) |
514 return this.domains; | 528 Object.defineProperty(this, "domains", {value: domains}); |
| 529 |
| 530 return domains; |
515 }, | 531 }, |
516 | 532 |
517 /** | 533 /** |
518 * Array containing public keys of websites that this filter should apply to | 534 * Array containing public keys of websites that this filter should apply to |
519 * @type {?string[]} | 535 * @type {?string[]} |
520 */ | 536 */ |
521 sitekeys: null, | 537 sitekeys: null, |
522 | 538 |
523 /** | 539 /** |
524 * Checks whether this filter is active on a domain. | 540 * Checks whether this filter is active on a domain. |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1253 |
1238 /** | 1254 /** |
1239 * Script that should be executed | 1255 * Script that should be executed |
1240 * @type {string} | 1256 * @type {string} |
1241 */ | 1257 */ |
1242 get script() | 1258 get script() |
1243 { | 1259 { |
1244 return this.body; | 1260 return this.body; |
1245 } | 1261 } |
1246 }); | 1262 }); |
OLD | NEW |