Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 let key; | 150 let key; |
151 do { | 151 do { |
152 key = Math.random().toFixed(15).substr(5); | 152 key = Math.random().toFixed(15).substr(5); |
153 } while (key in filterByKey); | 153 } while (key in filterByKey); |
154 | 154 |
155 filterByKey[key] = filter; | 155 filterByKey[key] = filter; |
156 keyByFilter[filter.text] = key; | 156 keyByFilter[filter.text] = key; |
157 | 157 |
158 if (usingFiltersByDomain) | 158 if (usingFiltersByDomain) |
159 { | 159 { |
160 let domainMatches = filter.domains || defaultDomains; | 160 let domains = filter.domains || defaultDomains; |
161 for (let domain in domainMatches) | 161 for (let domain in domains) |
162 { | 162 { |
163 let filters = filtersByDomain[domain]; | 163 let filters = filtersByDomain[domain]; |
164 if (!filters) | 164 if (!filters) |
165 filters = filtersByDomain[domain] = Object.create(null); | 165 filters = filtersByDomain[domain] = Object.create(null); |
166 | 166 |
167 if (domainMatches[domain]) | 167 if (domains[domain]) |
168 filters[filter.text] = filter; | 168 filters[filter.text] = filter; |
169 else | 169 else |
170 filters[filter.text] = false; | 170 filters[filter.text] = false; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 ElemHide.isDirty = true; | 174 ElemHide.isDirty = true; |
175 } | 175 } |
176 }, | 176 }, |
177 | 177 |
(...skipping 16 matching lines...) Expand all Loading... | |
194 } | 194 } |
195 else | 195 else |
196 { | 196 { |
197 if (!(filter.text in keyByFilter)) | 197 if (!(filter.text in keyByFilter)) |
198 return; | 198 return; |
199 | 199 |
200 let key = keyByFilter[filter.text]; | 200 let key = keyByFilter[filter.text]; |
201 delete filterByKey[key]; | 201 delete filterByKey[key]; |
202 delete keyByFilter[filter.text]; | 202 delete keyByFilter[filter.text]; |
203 ElemHide.isDirty = true; | 203 ElemHide.isDirty = true; |
204 } | 204 |
205 | 205 if (usingFiltersByDomain) |
206 if (usingFiltersByDomain) | 206 { |
207 { | 207 let domains = filter.domains || defaultDomains; |
208 let domains = Object.keys(filter.domains || defaultDomains); | 208 for (let domain in domains) |
Sebastian Noack
2016/05/20 12:20:44
So in the case here for..in would be actually slow
kzar
2016/05/20 12:49:29
Well I didn't think about it either way to be hone
kzar
2016/05/20 13:13:38
As we discussed in IRC I did a quick test of this
| |
209 for (let domain of domains) | 209 { |
210 { | 210 let filters = filtersByDomain[domain]; |
211 let filters = filtersByDomain[domain]; | 211 if (filters) |
212 if (filters) | 212 delete filters[filter.text]; |
213 delete filters[filter.text]; | 213 } |
kzar
2016/05/20 11:36:12
Note: There is a memory leak here. I don't delete
Wladimir Palant
2016/05/20 12:17:51
I don't think that this is a big deal. All filters
Sebastian Noack
2016/05/20 12:20:44
How did you try to delete filtersByDomain[domain]?
Sebastian Noack
2016/05/20 12:29:24
What if an element hiding filter is given in two s
Wladimir Palant
2016/05/20 12:40:05
Frankly, I don't care. No matter how you do it, it
Wladimir Palant
2016/05/20 12:40:05
That case is being handled elsewhere (FilterListen
kzar
2016/05/20 12:49:29
Whoops sorry, I moved this at the last minute and
kzar
2016/05/20 12:49:29
I didn't consider that. I'm not sure how we can ha
kzar
2016/05/20 12:49:29
Well I tried those ideas already except using .get
| |
214 } | 214 } |
215 } | 215 } |
216 }, | 216 }, |
217 | 217 |
218 /** | 218 /** |
219 * Checks whether an exception rule is registered for a filter on a particular | 219 * Checks whether an exception rule is registered for a filter on a particular |
220 * domain. | 220 * domain. |
221 */ | 221 */ |
222 getException: function(/**Filter*/ filter, /**String*/ docDomain) /**ElemHideE xception*/ | 222 getException: function(/**Filter*/ filter, /**String*/ docDomain) /**ElemHideE xception*/ |
223 { | 223 { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 if (currentDomain == "") | 451 if (currentDomain == "") |
452 break; | 452 break; |
453 | 453 |
454 let nextDot = currentDomain.indexOf("."); | 454 let nextDot = currentDomain.indexOf("."); |
455 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 455 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
456 } | 456 } |
457 | 457 |
458 return selectors; | 458 return selectors; |
459 } | 459 } |
460 }; | 460 }; |
LEFT | RIGHT |