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

Side by Side Diff: lib/filterClasses.js

Issue 29841558: Issue 6815 - Avoid multiple copies of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 29, 2018, 3:01 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Definition of Filter class and its subclasses. 21 * @fileOverview Definition of Filter class and its subclasses.
22 */ 22 */
23 23
24 const {FilterNotifier} = require("./filterNotifier"); 24 const {FilterNotifier} = require("./filterNotifier");
25 const {extend} = require("./coreUtils"); 25 const {extend} = require("./coreUtils");
26 const {filterToRegExp} = require("./common"); 26 const {filterToRegExp} = require("./common");
27 27
28 /** 28 /**
29 * All known unique domain sources mapped to their parsed values.
30 * @type {Map.<string,Map.<string,boolean>>}
31 */
32 let knownDomainMaps = new Map();
33
34 /**
29 * Abstract base class for filters 35 * Abstract base class for filters
30 * 36 *
31 * @param {string} text string representation of the filter 37 * @param {string} text string representation of the filter
32 * @constructor 38 * @constructor
33 */ 39 */
34 function Filter(text) 40 function Filter(text)
35 { 41 {
36 this.text = text; 42 this.text = text;
37 this.subscriptions = []; 43 this.subscriptions = [];
38 } 44 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 let domains = null; 415 let domains = null;
410 416
411 if (this.domainSource) 417 if (this.domainSource)
412 { 418 {
413 let source = this.domainSource; 419 let source = this.domainSource;
414 if (!this.domainSourceIsLowerCase) 420 if (!this.domainSourceIsLowerCase)
415 { 421 {
416 // RegExpFilter already have lowercase domains 422 // RegExpFilter already have lowercase domains
417 source = source.toLowerCase(); 423 source = source.toLowerCase();
418 } 424 }
419 let list = source.split(this.domainSeparator); 425
420 if (list.length == 1 && list[0][0] != "~") 426 let knownMap = knownDomainMaps.get(source);
427 if (knownMap)
421 { 428 {
422 // Fast track for the common one-domain scenario 429 domains = knownMap;
423 domains = list[0];
424 } 430 }
425 else 431 else
426 { 432 {
427 let hasIncludes = false; 433 let list = source.split(this.domainSeparator);
428 for (let i = 0; i < list.length; i++) 434 if (list.length == 1 && list[0][0] != "~")
429 { 435 {
430 let domain = list[i]; 436 // Fast track for the common one-domain scenario
431 if (domain == "") 437 domains = list[0];
432 continue; 438 }
439 else
440 {
441 let hasIncludes = false;
442 for (let i = 0; i < list.length; i++)
443 {
444 let domain = list[i];
445 if (domain == "")
446 continue;
433 447
434 let include; 448 let include;
435 if (domain[0] == "~") 449 if (domain[0] == "~")
436 { 450 {
437 include = false; 451 include = false;
438 domain = domain.substr(1); 452 domain = domain.substr(1);
439 } 453 }
440 else 454 else
441 { 455 {
442 include = true; 456 include = true;
443 hasIncludes = true; 457 hasIncludes = true;
458 }
459
460 if (!domains)
461 domains = new Map();
462
463 domains.set(domain, include);
444 } 464 }
445 465
446 if (!domains) 466 if (domains)
447 domains = new Map(); 467 {
448 468 domains.set("", !hasIncludes);
449 domains.set(domain, include); 469 knownDomainMaps.set(source, domains);
470 }
450 } 471 }
451 if (domains)
452 domains.set("", !hasIncludes);
453 } 472 }
454 473
455 this.domainSource = null; 474 this.domainSource = null;
456 } 475 }
457 476
458 Object.defineProperty(this, "_domains", {value: domains}); 477 Object.defineProperty(this, "_domains", {value: domains});
459 return this.domains; 478 return this.domains;
460 }, 479 },
461 480
462 /** 481 /**
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 1186
1168 /** 1187 /**
1169 * Script that should be executed 1188 * Script that should be executed
1170 * @type {string} 1189 * @type {string}
1171 */ 1190 */
1172 get script() 1191 get script()
1173 { 1192 {
1174 return this.body; 1193 return this.body;
1175 } 1194 }
1176 }); 1195 });
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