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

Side by Side Diff: lib/elemHide.js

Issue 29909555: Issue 7046 - Defer caching of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Do not cache value for generic filters Created Oct. 14, 2018, 12:26 a.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 | lib/filterClasses.js » ('j') | lib/filterClasses.js » ('J')
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 let index = domain.indexOf("."); 104 let index = domain.indexOf(".");
105 domain = index == -1 ? "" : domain.substring(index + 1); 105 domain = index == -1 ? "" : domain.substring(index + 1);
106 } 106 }
107 107
108 return domain; 108 return domain;
109 } 109 }
110 110
111 /** 111 /**
112 * Adds a filter to the lookup table of filters by domain. 112 * Adds a filter to the lookup table of filters by domain.
113 * @param {Filter} filter 113 * @param {Filter} filter
114 * @param {?Map.<string,boolean>} [domains]
114 */ 115 */
115 function addToFiltersByDomain(filter) 116 function addToFiltersByDomain(filter, domains = filter.domains)
116 { 117 {
117 let domains = filter.domains || defaultDomains; 118 for (let [domain, isIncluded] of domains || defaultDomains)
118 for (let [domain, isIncluded] of domains)
119 { 119 {
120 // There's no need to note that a filter is generically disabled. 120 // There's no need to note that a filter is generically disabled.
121 if (!isIncluded && domain == "") 121 if (!isIncluded && domain == "")
122 continue; 122 continue;
123 123
124 let filters = filtersByDomain.get(domain); 124 let filters = filtersByDomain.get(domain);
125 if (!filters) 125 if (!filters)
126 filtersByDomain.set(domain, filters = new Map()); 126 filtersByDomain.set(domain, filters = new Map());
127 filters.set(filter, isIncluded); 127 filters.set(filter, isIncluded);
128 } 128 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 * Add a new element hiding filter 278 * Add a new element hiding filter
279 * @param {ElemHideFilter} filter 279 * @param {ElemHideFilter} filter
280 */ 280 */
281 add(filter) 281 add(filter)
282 { 282 {
283 if (knownFilters.has(filter)) 283 if (knownFilters.has(filter))
284 return; 284 return;
285 285
286 commonStyleSheet = null; 286 commonStyleSheet = null;
287 287
288 let {selector} = filter; 288 let {domains, selector} = filter;
289 289
290 if (!(filter.domains || ElemHideExceptions.hasExceptions(selector))) 290 if (!(domains || ElemHideExceptions.hasExceptions(selector)))
291 { 291 {
292 // The new filter's selector is unconditionally applied to all domains 292 // The new filter's selector is unconditionally applied to all domains
293 filterBySelector.set(selector, filter); 293 filterBySelector.set(selector, filter);
294 unconditionalSelectors = null; 294 unconditionalSelectors = null;
295 defaultStyleSheet = null; 295 defaultStyleSheet = null;
296 } 296 }
297 else 297 else
298 { 298 {
299 // The new filter's selector only applies to some domains 299 // The new filter's selector only applies to some domains
300 addToFiltersByDomain(filter); 300 addToFiltersByDomain(filter, domains);
301 } 301 }
302 302
303 knownFilters.add(filter); 303 knownFilters.add(filter);
304 filterNotifier.emit("elemhideupdate"); 304 filterNotifier.emit("elemhideupdate");
305 }, 305 },
306 306
307 /** 307 /**
308 * Removes an element hiding filter 308 * Removes an element hiding filter
309 * @param {ElemHideFilter} filter 309 * @param {ElemHideFilter} filter
310 */ 310 */
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 { 479 {
480 let styleSheet = ""; 480 let styleSheet = "";
481 481
482 for (let selectorGroup of splitSelectors(selectors)) 482 for (let selectorGroup of splitSelectors(selectors))
483 styleSheet += createRule(selectorGroup); 483 styleSheet += createRule(selectorGroup);
484 484
485 return styleSheet; 485 return styleSheet;
486 } 486 }
487 487
488 exports.createStyleSheet = createStyleSheet; 488 exports.createStyleSheet = createStyleSheet;
OLDNEW
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | lib/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld