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

Side by Side Diff: lib/filterClasses.js

Issue 29791555: Issue 6727 - Use string rather than map for single-domain filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Use temporary Map objects Created June 6, 2018, 12:13 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 /** 395 /**
396 * Map containing domains that this filter should match on/not match 396 * Map containing domains that this filter should match on/not match
397 * on or null if the filter should match on all domains 397 * on or null if the filter should match on all domains
398 * @type {?Map.<string,boolean>} 398 * @type {?Map.<string,boolean>}
399 */ 399 */
400 get domains() 400 get domains()
401 { 401 {
402 // Despite this property being cached, the getter is called 402 // Despite this property being cached, the getter is called
403 // several times on Safari, due to WebKit bug 132872 403 // several times on Safari, due to WebKit bug 132872
404 let prop = Object.getOwnPropertyDescriptor(this, "domains"); 404 let prop = Object.getOwnPropertyDescriptor(this, "_domains");
405 if (prop) 405 if (prop)
406 return prop.value; 406 {
407 let {value} = prop;
408 return typeof value == "string" ?
409 new Map([[value, true], ["", false]]) : value;
410 }
407 411
408 let domains = null; 412 let domains = null;
409 413
410 if (this.domainSource) 414 if (this.domainSource)
411 { 415 {
412 let source = this.domainSource; 416 let source = this.domainSource;
413 if (!this.domainSourceIsUpperCase) 417 if (!this.domainSourceIsUpperCase)
414 { 418 {
415 // RegExpFilter already have uppercase domains 419 // RegExpFilter already have uppercase domains
416 source = source.toUpperCase(); 420 source = source.toUpperCase();
417 } 421 }
418 let list = source.split(this.domainSeparator); 422 let list = source.split(this.domainSeparator);
419 if (list.length == 1 && list[0][0] != "~") 423 if (list.length == 1 && list[0][0] != "~")
420 { 424 {
421 // Fast track for the common one-domain scenario 425 // Fast track for the common one-domain scenario
422 domains = new Map([["", false], [list[0], true]]); 426 domains = list[0];
423 } 427 }
424 else 428 else
425 { 429 {
426 let hasIncludes = false; 430 let hasIncludes = false;
427 for (let i = 0; i < list.length; i++) 431 for (let i = 0; i < list.length; i++)
428 { 432 {
429 let domain = list[i]; 433 let domain = list[i];
430 if (domain == "") 434 if (domain == "")
431 continue; 435 continue;
432 436
(...skipping 14 matching lines...) Expand all
447 451
448 domains.set(domain, include); 452 domains.set(domain, include);
449 } 453 }
450 if (domains) 454 if (domains)
451 domains.set("", !hasIncludes); 455 domains.set("", !hasIncludes);
452 } 456 }
453 457
454 this.domainSource = null; 458 this.domainSource = null;
455 } 459 }
456 460
457 Object.defineProperty(this, "domains", {value: domains, enumerable: true}); 461 Object.defineProperty(this, "_domains", {value: domains});
458 return this.domains; 462 return this.domains;
459 }, 463 },
460 464
461 /** 465 /**
462 * Array containing public keys of websites that this filter should apply to 466 * Array containing public keys of websites that this filter should apply to
463 * @type {?string[]} 467 * @type {?string[]}
464 */ 468 */
465 sitekeys: null, 469 sitekeys: null,
466 470
467 /** 471 /**
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 */ 1103 */
1100 function ElemHideEmulationFilter(text, domains, selector) 1104 function ElemHideEmulationFilter(text, domains, selector)
1101 { 1105 {
1102 ElemHideBase.call(this, text, domains, selector); 1106 ElemHideBase.call(this, text, domains, selector);
1103 } 1107 }
1104 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1108 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1105 1109
1106 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1110 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1107 type: "elemhideemulation" 1111 type: "elemhideemulation"
1108 }); 1112 });
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