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