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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 29551638: Issue 5735 - Use JS Map instead of Object for global keyByFilter in elemHide.js (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: Created Sept. 21, 2017, 11:47 a.m.
Right Patch Set: use objects as keys Created Sept. 25, 2017, 1:39 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 | no next file » | 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 13 matching lines...) Expand all
24 const {ElemHideException} = require("filterClasses"); 24 const {ElemHideException} = require("filterClasses");
25 const {FilterNotifier} = require("filterNotifier"); 25 const {FilterNotifier} = require("filterNotifier");
26 26
27 /** 27 /**
28 * Lookup table, filters by their associated key 28 * Lookup table, filters by their associated key
29 * @type {Object} 29 * @type {Object}
30 */ 30 */
31 let filterByKey = []; 31 let filterByKey = [];
32 32
33 /** 33 /**
34 * Lookup table, keys of the filters by filter text 34 * Lookup table, keys of the filters by filter
35 * @type {Map.<string,string>} 35 * @type {Map.<Filter,string>}
sergei 2017/09/21 12:02:10 Pay attention that after switching from Object to
kzar 2017/09/22 10:50:15 Yea, it looks like we only used the Filter's text
Wladimir Palant 2017/09/25 10:59:31 Agreed, we should use Filter objects as keys here.
sergei 2017/09/25 13:41:23 Done. I have checked when the type of key here is
Wladimir Palant 2017/09/25 13:57:16 A change in memory usage would be unexpected, both
36 */ 36 */
37 let keyByFilter = new Map(); 37 let keyByFilter = new Map();
38 38
39 /** 39 /**
40 * Nested lookup table, filter (or false if inactive) by filter key by domain. 40 * Nested lookup table, filter (or false if inactive) by filter key by domain.
41 * (Only contains filters that aren't unconditionally matched for all domains.) 41 * (Only contains filters that aren't unconditionally matched for all domains.)
42 * @type {Map.<string,Map.<string,(Filter|boolean)>>} 42 * @type {Map.<string,Map.<string,(Filter|boolean)>>}
43 */ 43 */
44 let filtersByDomain = new Map(); 44 let filtersByDomain = new Map();
45 45
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 { 136 {
137 this._addToFiltersByDomain(filterKey, filterByKey[filterKey]); 137 this._addToFiltersByDomain(filterKey, filterByKey[filterKey]);
138 delete filterKeyBySelector[selector]; 138 delete filterKeyBySelector[selector];
139 unconditionalSelectors = unconditionalFilterKeys = null; 139 unconditionalSelectors = unconditionalFilterKeys = null;
140 } 140 }
141 141
142 knownExceptions[filter.text] = true; 142 knownExceptions[filter.text] = true;
143 } 143 }
144 else 144 else
145 { 145 {
146 if (keyByFilter.has(filter.text)) 146 if (keyByFilter.has(filter))
147 return; 147 return;
148 148
149 let key = filterByKey.push(filter) - 1; 149 let key = filterByKey.push(filter) - 1;
150 keyByFilter.set(filter.text, key); 150 keyByFilter.set(filter, key);
151 151
152 if (!(filter.domains || filter.selector in exceptions)) 152 if (!(filter.domains || filter.selector in exceptions))
153 { 153 {
154 // The new filter's selector is unconditionally applied to all domains 154 // The new filter's selector is unconditionally applied to all domains
155 filterKeyBySelector[filter.selector] = key; 155 filterKeyBySelector[filter.selector] = key;
156 unconditionalSelectors = unconditionalFilterKeys = null; 156 unconditionalSelectors = unconditionalFilterKeys = null;
157 } 157 }
158 else 158 else
159 { 159 {
160 // The new filter's selector only applies to some domains 160 // The new filter's selector only applies to some domains
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return; 197 return;
198 198
199 let list = exceptions[filter.selector]; 199 let list = exceptions[filter.selector];
200 let index = list.indexOf(filter); 200 let index = list.indexOf(filter);
201 if (index >= 0) 201 if (index >= 0)
202 list.splice(index, 1); 202 list.splice(index, 1);
203 delete knownExceptions[filter.text]; 203 delete knownExceptions[filter.text];
204 } 204 }
205 else 205 else
206 { 206 {
207 let key = keyByFilter.get(filter.text); 207 let key = keyByFilter.get(filter);
208 if (typeof key == "undefined") 208 if (typeof key == "undefined")
209 return; 209 return;
210 210
211 delete filterByKey[key]; 211 delete filterByKey[key];
212 keyByFilter.delete(filter.text); 212 keyByFilter.delete(filter);
213 this._removeFilterKey(key, filter); 213 this._removeFilterKey(key, filter);
214 } 214 }
215 215
216 FilterNotifier.emit("elemhideupdate"); 216 FilterNotifier.emit("elemhideupdate");
217 }, 217 },
218 218
219 /** 219 /**
220 * Checks whether an exception rule is registered for a filter on a particular 220 * Checks whether an exception rule is registered for a filter on a particular
221 * domain. 221 * domain.
222 * @param {Filter} filter 222 * @param {Filter} filter
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 let nextDot = currentDomain.indexOf("."); 382 let nextDot = currentDomain.indexOf(".");
383 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 383 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
384 } 384 }
385 385
386 if (provideFilterKeys) 386 if (provideFilterKeys)
387 return [selectors, filterKeys]; 387 return [selectors, filterKeys];
388 return selectors; 388 return selectors;
389 } 389 }
390 }; 390 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld