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

Side by Side Diff: lib/elemHide.js

Issue 29550662: Issue 5735 - Use JS Map instead of Object for property domains of Filter objects (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: Created Sept. 20, 2017, 12:59 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 | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 /** 59 /**
60 * This array caches the values of filterKeyBySelector table (filterIds for 60 * This array caches the values of filterKeyBySelector table (filterIds for
61 * selectors which unconditionally apply on all domains). It will be null if the 61 * selectors which unconditionally apply on all domains). It will be null if the
62 * cache needs to be rebuilt. 62 * cache needs to be rebuilt.
63 */ 63 */
64 let unconditionalFilterKeys = null; 64 let unconditionalFilterKeys = null;
65 65
66 /** 66 /**
67 * Object to be used instead when a filter has a blank domains property. 67 * Object to be used instead when a filter has a blank domains property.
68 */ 68 */
69 let defaultDomains = Object.create(null); 69 let defaultDomains = new Map();
70 defaultDomains[""] = true; 70 defaultDomains.set("", true);
Wladimir Palant 2017/09/21 08:11:44 You can initialize the Map object immediately: new
sergei 2017/09/21 10:50:33 Done.
71 71
72 /** 72 /**
73 * Lookup table, keys are known element hiding exceptions 73 * Lookup table, keys are known element hiding exceptions
74 * @type {Object} 74 * @type {Object}
75 */ 75 */
76 let knownExceptions = Object.create(null); 76 let knownExceptions = Object.create(null);
77 77
78 /** 78 /**
79 * Lookup table, lists of element hiding exceptions by selector 79 * Lookup table, lists of element hiding exceptions by selector
80 * @type {Object} 80 * @type {Object}
(...skipping 16 matching lines...) Expand all
97 filterKeyBySelector = Object.create(null); 97 filterKeyBySelector = Object.create(null);
98 unconditionalSelectors = unconditionalFilterKeys = null; 98 unconditionalSelectors = unconditionalFilterKeys = null;
99 knownExceptions = Object.create(null); 99 knownExceptions = Object.create(null);
100 exceptions = Object.create(null); 100 exceptions = Object.create(null);
101 FilterNotifier.emit("elemhideupdate"); 101 FilterNotifier.emit("elemhideupdate");
102 }, 102 },
103 103
104 _addToFiltersByDomain(key, filter) 104 _addToFiltersByDomain(key, filter)
105 { 105 {
106 let domains = filter.domains || defaultDomains; 106 let domains = filter.domains || defaultDomains;
107 for (let domain in domains) 107 for (let [domain, isIncluded] of domains)
108 { 108 {
109 let filters = filtersByDomain[domain]; 109 let filters = filtersByDomain[domain];
110 if (!filters) 110 if (!filters)
111 filters = filtersByDomain[domain] = Object.create(null); 111 filters = filtersByDomain[domain] = Object.create(null);
Wladimir Palant 2017/09/21 08:11:44 Shouldn't this be turned in to a Map object as wel
sergei 2017/09/21 10:50:33 No, I find the change of filtersByDomain self-cont
112 112
113 if (domains[domain]) 113 if (isIncluded)
114 filters[key] = filter; 114 filters[key] = filter;
115 else 115 else
116 filters[key] = false; 116 filters[key] = false;
117 } 117 }
118 }, 118 },
119 119
120 /** 120 /**
121 * Add a new element hiding filter 121 * Add a new element hiding filter
122 * @param {ElemHideFilter} filter 122 * @param {ElemHideFilter} filter
123 */ 123 */
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (filterKeyBySelector[filter.selector] == key) 175 if (filterKeyBySelector[filter.selector] == key)
176 { 176 {
177 delete filterKeyBySelector[filter.selector]; 177 delete filterKeyBySelector[filter.selector];
178 unconditionalSelectors = unconditionalFilterKeys = null; 178 unconditionalSelectors = unconditionalFilterKeys = null;
179 return; 179 return;
180 } 180 }
181 181
182 // We haven't found this filter in unconditional filters, look in 182 // We haven't found this filter in unconditional filters, look in
183 // filtersByDomain. 183 // filtersByDomain.
184 let domains = filter.domains || defaultDomains; 184 let domains = filter.domains || defaultDomains;
185 for (let domain in domains) 185 for (let domain of domains.keys())
186 { 186 {
187 let filters = filtersByDomain[domain]; 187 let filters = filtersByDomain[domain];
188 if (filters) 188 if (filters)
189 delete filters[key]; 189 delete filters[key];
190 } 190 }
191 }, 191 },
192 192
193 /** 193 /**
194 * Removes an element hiding filter 194 * Removes an element hiding filter
195 * @param {ElemHideFilter} filter 195 * @param {ElemHideFilter} filter
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 let nextDot = currentDomain.indexOf("."); 388 let nextDot = currentDomain.indexOf(".");
389 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 389 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
390 } 390 }
391 391
392 if (provideFilterKeys) 392 if (provideFilterKeys)
393 return [selectors, filterKeys]; 393 return [selectors, filterKeys];
394 return selectors; 394 return selectors;
395 } 395 }
396 }; 396 };
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