Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterClasses.js

Issue 29841555: Issue 6814 - Avoid redundant calls to domains getter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 29, 2018, 12:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 { 475 {
476 // Sitekeys are case-sensitive so we shouldn't convert them to 476 // Sitekeys are case-sensitive so we shouldn't convert them to
477 // upper-case to avoid false positives here. Instead we need to 477 // upper-case to avoid false positives here. Instead we need to
478 // change the way filter options are parsed. 478 // change the way filter options are parsed.
479 if (this.sitekeys && 479 if (this.sitekeys &&
480 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) 480 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0))
481 { 481 {
482 return false; 482 return false;
483 } 483 }
484 484
485 let {domains} = this;
486
485 // If no domains are set the rule matches everywhere 487 // If no domains are set the rule matches everywhere
486 if (!this.domains) 488 if (!domains)
487 return true; 489 return true;
488 490
489 // If the document has no host name, match only if the filter 491 // If the document has no host name, match only if the filter
490 // isn't restricted to specific domains 492 // isn't restricted to specific domains
491 if (!docDomain) 493 if (!docDomain)
492 return this.domains.get(""); 494 return domains.get("");
493 495
494 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); 496 docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
495 497
496 while (true) 498 while (true)
497 { 499 {
498 let isDomainIncluded = this.domains.get(docDomain); 500 let isDomainIncluded = domains.get(docDomain);
499 if (typeof isDomainIncluded != "undefined") 501 if (typeof isDomainIncluded != "undefined")
500 return isDomainIncluded; 502 return isDomainIncluded;
501 503
502 let nextDot = docDomain.indexOf("."); 504 let nextDot = docDomain.indexOf(".");
503 if (nextDot < 0) 505 if (nextDot < 0)
504 break; 506 break;
505 docDomain = docDomain.substr(nextDot + 1); 507 docDomain = docDomain.substr(nextDot + 1);
506 } 508 }
507 return this.domains.get(""); 509 return domains.get("");
508 }, 510 },
509 511
510 /** 512 /**
511 * Checks whether this filter is active only on a domain and its subdomains. 513 * Checks whether this filter is active only on a domain and its subdomains.
512 * @param {string} docDomain 514 * @param {string} docDomain
513 * @return {boolean} 515 * @return {boolean}
514 */ 516 */
515 isActiveOnlyOnDomain(docDomain) 517 isActiveOnlyOnDomain(docDomain)
516 { 518 {
517 if (!docDomain || !this.domains || this.domains.get("")) 519 let {domains} = this;
520
521 if (!docDomain || !domains || domains.get(""))
518 return false; 522 return false;
519 523
520 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); 524 docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
521 525
522 for (let [domain, isIncluded] of this.domains) 526 for (let [domain, isIncluded] of domains)
523 { 527 {
524 if (isIncluded && domain != docDomain) 528 if (isIncluded && domain != docDomain)
525 { 529 {
526 if (domain.length <= docDomain.length) 530 if (domain.length <= docDomain.length)
527 return false; 531 return false;
528 532
529 if (!domain.endsWith("." + docDomain)) 533 if (!domain.endsWith("." + docDomain))
530 return false; 534 return false;
531 } 535 }
532 } 536 }
533 537
534 return true; 538 return true;
535 }, 539 },
536 540
537 /** 541 /**
538 * Checks whether this filter is generic or specific 542 * Checks whether this filter is generic or specific
539 * @return {boolean} 543 * @return {boolean}
540 */ 544 */
541 isGeneric() 545 isGeneric()
542 { 546 {
547 let {domains} = this;
548
543 return !(this.sitekeys && this.sitekeys.length) && 549 return !(this.sitekeys && this.sitekeys.length) &&
544 (!this.domains || this.domains.get("")); 550 (!domains || domains.get(""));
545 }, 551 },
546 552
547 /** 553 /**
548 * See Filter.serialize() 554 * See Filter.serialize()
549 * @inheritdoc 555 * @inheritdoc
550 */ 556 */
551 serialize(buffer) 557 serialize(buffer)
552 { 558 {
553 if (this._disabled || this._hitCount || this._lastHit) 559 if (this._disabled || this._hitCount || this._lastHit)
554 { 560 {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 1173
1168 /** 1174 /**
1169 * Script that should be executed 1175 * Script that should be executed
1170 * @type {string} 1176 * @type {string}
1171 */ 1177 */
1172 get script() 1178 get script()
1173 { 1179 {
1174 return this.body; 1180 return this.body;
1175 } 1181 }
1176 }); 1182 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld