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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 domainSource: null, | 440 domainSource: null, |
441 | 441 |
442 /** | 442 /** |
443 * Separator character used in domainSource property, must be | 443 * Separator character used in domainSource property, must be |
444 * overridden by subclasses | 444 * overridden by subclasses |
445 * @type {string} | 445 * @type {string} |
446 */ | 446 */ |
447 domainSeparator: null, | 447 domainSeparator: null, |
448 | 448 |
449 /** | 449 /** |
| 450 * Internal counter to keep track of the number of times the |
| 451 * {@link ActiveFilter#domains} property is accessed. |
| 452 * @type {number} |
| 453 * @private |
| 454 */ |
| 455 _domainsAccessCount: 0, |
| 456 |
| 457 /** |
| 458 * Maximum number of times the {@link ActiveFilter#domains} property can be |
| 459 * accessed before the value is cached. |
| 460 * @type {number} |
| 461 * @private |
| 462 */ |
| 463 _domainsAccessCacheThreshold: 3, |
| 464 |
| 465 /** |
450 * Map containing domains that this filter should match on/not match | 466 * Map containing domains that this filter should match on/not match |
451 * on or null if the filter should match on all domains | 467 * on or null if the filter should match on all domains |
452 * @type {?Map.<string,boolean>} | 468 * @type {?Map.<string,boolean>} |
453 */ | 469 */ |
454 get domains() | 470 get domains() |
455 { | 471 { |
| 472 // For some filter types this property is accessed only rarely, especially |
| 473 // when the subscriptions are initially loaded. We defer any caching for |
| 474 // such filters. |
| 475 let cacheValue = ++this._domainsAccessCount > |
| 476 this._domainsAccessCacheThreshold; |
| 477 |
456 let domains = null; | 478 let domains = null; |
457 | 479 |
458 if (this.domainSource) | 480 if (this.domainSource) |
459 { | 481 { |
460 let source = this.domainSource.toLowerCase(); | 482 let source = this.domainSource.toLowerCase(); |
461 | 483 |
462 let knownMap = knownDomainMaps.get(source); | 484 let knownMap = knownDomainMaps.get(source); |
463 if (knownMap) | 485 if (knownMap) |
464 { | 486 { |
465 domains = knownMap; | 487 domains = knownMap; |
(...skipping 30 matching lines...) Expand all Loading... |
496 if (!domains) | 518 if (!domains) |
497 domains = new Map(); | 519 domains = new Map(); |
498 | 520 |
499 domains.set(domain, include); | 521 domains.set(domain, include); |
500 } | 522 } |
501 | 523 |
502 if (domains) | 524 if (domains) |
503 domains.set("", !hasIncludes); | 525 domains.set("", !hasIncludes); |
504 } | 526 } |
505 | 527 |
506 if (domains) | 528 if (!domains || cacheValue) |
507 knownDomainMaps.set(source, domains); | 529 knownDomainMaps.set(source, domains); |
508 } | 530 } |
509 | 531 |
510 this.domainSource = null; | 532 if (!domains || cacheValue) |
| 533 this.domainSource = null; |
511 } | 534 } |
512 | 535 |
513 Object.defineProperty(this, "domains", {value: domains}); | 536 if (!domains || cacheValue) |
514 return this.domains; | 537 Object.defineProperty(this, "domains", {value: domains}); |
| 538 |
| 539 return domains; |
515 }, | 540 }, |
516 | 541 |
517 /** | 542 /** |
518 * Array containing public keys of websites that this filter should apply to | 543 * Array containing public keys of websites that this filter should apply to |
519 * @type {?string[]} | 544 * @type {?string[]} |
520 */ | 545 */ |
521 sitekeys: null, | 546 sitekeys: null, |
522 | 547 |
523 /** | 548 /** |
524 * Checks whether this filter is active on a domain. | 549 * Checks whether this filter is active on a domain. |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1262 |
1238 /** | 1263 /** |
1239 * Script that should be executed | 1264 * Script that should be executed |
1240 * @type {string} | 1265 * @type {string} |
1241 */ | 1266 */ |
1242 get script() | 1267 get script() |
1243 { | 1268 { |
1244 return this.body; | 1269 return this.body; |
1245 } | 1270 } |
1246 }); | 1271 }); |
OLD | NEW |