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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29841558: Issue 6815 - Avoid multiple copies of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebase Created July 30, 2018, 4:35 p.m.
Right Patch Set: Add tests Created July 30, 2018, 5:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 */ 397 */
398 domainSourceIsLowerCase: false, 398 domainSourceIsLowerCase: false,
399 399
400 /** 400 /**
401 * Map containing domains that this filter should match on/not match 401 * Map containing domains that this filter should match on/not match
402 * on or null if the filter should match on all domains 402 * on or null if the filter should match on all domains
403 * @type {?Map.<string,boolean>} 403 * @type {?Map.<string,boolean>}
404 */ 404 */
405 get domains() 405 get domains()
406 { 406 {
407 let prop = Object.getOwnPropertyDescriptor(this, "_domains");
408 if (prop)
409 {
410 let {value} = prop;
411 return typeof value == "string" ?
412 new Map([[value, true], ["", false]]) : value;
413 }
414
415 let domains = null; 407 let domains = null;
416 408
417 if (this.domainSource) 409 if (this.domainSource)
418 { 410 {
419 let source = this.domainSource; 411 let source = this.domainSource;
420 if (!this.domainSourceIsLowerCase) 412 if (!this.domainSourceIsLowerCase)
421 { 413 {
422 // RegExpFilter already have lowercase domains 414 // RegExpFilter already have lowercase domains
423 source = source.toLowerCase(); 415 source = source.toLowerCase();
424 } 416 }
425 417
426 let knownMap = knownDomainMaps.get(source); 418 let knownMap = knownDomainMaps.get(source);
427 if (knownMap) 419 if (knownMap)
428 { 420 {
429 domains = knownMap; 421 domains = knownMap;
430 } 422 }
431 else 423 else
432 { 424 {
433 let list = source.split(this.domainSeparator); 425 let list = source.split(this.domainSeparator);
434 if (list.length == 1 && list[0][0] != "~") 426 if (list.length == 1 && list[0][0] != "~")
435 { 427 {
436 // Fast track for the common one-domain scenario 428 // Fast track for the common one-domain scenario
437 domains = list[0]; 429 domains = new Map([[list[0], true], ["", false]]);
438 } 430 }
439 else 431 else
440 { 432 {
441 let hasIncludes = false; 433 let hasIncludes = false;
442 for (let i = 0; i < list.length; i++) 434 for (let i = 0; i < list.length; i++)
443 { 435 {
444 let domain = list[i]; 436 let domain = list[i];
445 if (domain == "") 437 if (domain == "")
446 continue; 438 continue;
447 439
448 let include; 440 let include;
449 if (domain[0] == "~") 441 if (domain[0] == "~")
450 { 442 {
451 include = false; 443 include = false;
452 domain = domain.substr(1); 444 domain = domain.substr(1);
453 } 445 }
454 else 446 else
455 { 447 {
456 include = true; 448 include = true;
457 hasIncludes = true; 449 hasIncludes = true;
458 } 450 }
459 451
460 if (!domains) 452 if (!domains)
461 domains = new Map(); 453 domains = new Map();
462 454
463 domains.set(domain, include); 455 domains.set(domain, include);
464 } 456 }
465 457
466 if (domains) 458 if (domains)
467 {
468 domains.set("", !hasIncludes); 459 domains.set("", !hasIncludes);
469 knownDomainMaps.set(source, domains);
470 }
471 } 460 }
461
462 if (domains)
463 knownDomainMaps.set(source, domains);
472 } 464 }
473 465
474 this.domainSource = null; 466 this.domainSource = null;
475 } 467 }
476 468
477 Object.defineProperty(this, "_domains", {value: domains}); 469 Object.defineProperty(this, "domains", {value: domains});
478 return this.domains; 470 return this.domains;
479 }, 471 },
480 472
481 /** 473 /**
482 * Array containing public keys of websites that this filter should apply to 474 * Array containing public keys of websites that this filter should apply to
483 * @type {?string[]} 475 * @type {?string[]}
484 */ 476 */
485 sitekeys: null, 477 sitekeys: null,
486 478
487 /** 479 /**
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 1183
1192 /** 1184 /**
1193 * Script that should be executed 1185 * Script that should be executed
1194 * @type {string} 1186 * @type {string}
1195 */ 1187 */
1196 get script() 1188 get script()
1197 { 1189 {
1198 return this.body; 1190 return this.body;
1199 } 1191 }
1200 }); 1192 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld