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

Side by Side Diff: lib/filterClasses.js

Issue 29816555: Issue 6727 - Avoid getter for multi-domain cases (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 26, 2018, 5:02 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 */ 393 */
394 domainSourceIsLowerCase: false, 394 domainSourceIsLowerCase: false,
395 395
396 /** 396 /**
397 * Map containing domains that this filter should match on/not match 397 * Map containing domains that this filter should match on/not match
398 * on or null if the filter should match on all domains 398 * on or null if the filter should match on all domains
399 * @type {?Map.<string,boolean>} 399 * @type {?Map.<string,boolean>}
400 */ 400 */
401 get domains() 401 get domains()
402 { 402 {
403 let prop = Object.getOwnPropertyDescriptor(this, "_domains");
404 if (prop)
405 {
406 let {value} = prop;
407 return typeof value == "string" ?
408 new Map([[value, true], ["", false]]) : value;
409 }
410
411 let domains = null; 403 let domains = null;
412 404
413 if (this.domainSource) 405 if (this.domainSource)
414 { 406 {
415 let source = this.domainSource; 407 let source = this.domainSource;
416 if (!this.domainSourceIsLowerCase) 408 if (!this.domainSourceIsLowerCase)
417 { 409 {
418 // RegExpFilter already have lowercase domains 410 // RegExpFilter already have lowercase domains
419 source = source.toLowerCase(); 411 source = source.toLowerCase();
420 } 412 }
421 let list = source.split(this.domainSeparator); 413 let list = source.split(this.domainSeparator);
422 if (list.length == 1 && list[0][0] != "~") 414 if (list.length == 1 && list[0][0] != "~")
423 { 415 {
424 // Fast track for the common one-domain scenario 416 // Fast track for the common one-domain scenario
425 domains = list[0]; 417 Object.defineProperty(this, "_singleDomain", {value: list[0]});
426 } 418 }
427 else 419 else
428 { 420 {
429 let hasIncludes = false; 421 let hasIncludes = false;
430 for (let i = 0; i < list.length; i++) 422 for (let i = 0; i < list.length; i++)
431 { 423 {
432 let domain = list[i]; 424 let domain = list[i];
433 if (domain == "") 425 if (domain == "")
434 continue; 426 continue;
435 427
436 let include; 428 let include;
437 if (domain[0] == "~") 429 if (domain[0] == "~")
438 { 430 {
439 include = false; 431 include = false;
440 domain = domain.substr(1); 432 domain = domain.substr(1);
441 } 433 }
442 else 434 else
443 { 435 {
444 include = true; 436 include = true;
445 hasIncludes = true; 437 hasIncludes = true;
446 } 438 }
447 439
448 if (!domains) 440 if (!domains)
441 {
449 domains = new Map(); 442 domains = new Map();
443 Object.defineProperty(this, "domains", {value: domains});
444 }
450 445
451 domains.set(domain, include); 446 domains.set(domain, include);
452 } 447 }
453 if (domains) 448 if (domains)
454 domains.set("", !hasIncludes); 449 domains.set("", !hasIncludes);
455 } 450 }
456 451
457 this.domainSource = null; 452 this.domainSource = null;
458 } 453 }
459 454
460 Object.defineProperty(this, "_domains", {value: domains}); 455 let singleDomain = this._singleDomain;
461 return this.domains; 456 if (singleDomain)
457 return new Map([[singleDomain, true], ["", false]]);
458
459 return domains;
462 }, 460 },
463 461
464 /** 462 /**
465 * Array containing public keys of websites that this filter should apply to 463 * Array containing public keys of websites that this filter should apply to
466 * @type {?string[]} 464 * @type {?string[]}
467 */ 465 */
468 sitekeys: null, 466 sitekeys: null,
469 467
470 /** 468 /**
471 * Checks whether this filter is active on a domain. 469 * Checks whether this filter is active on a domain.
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 */ 1106 */
1109 function ElemHideEmulationFilter(text, domains, selector) 1107 function ElemHideEmulationFilter(text, domains, selector)
1110 { 1108 {
1111 ElemHideBase.call(this, text, domains, selector); 1109 ElemHideBase.call(this, text, domains, selector);
1112 } 1110 }
1113 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1111 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1114 1112
1115 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1113 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1116 type: "elemhideemulation" 1114 type: "elemhideemulation"
1117 }); 1115 });
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