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

Side by Side Diff: lib/elemHide.js

Issue 29774573: Issue 6652 - Do not push to unconditional selectors array (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase Created May 11, 2018, 7:21 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 | 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
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 */ 59 */
60 let knownFilters = new Set(); 60 let knownFilters = new Set();
61 61
62 /** 62 /**
63 * Lookup table, lists of element hiding exceptions by selector 63 * Lookup table, lists of element hiding exceptions by selector
64 * @type {Map.<string,Filter>} 64 * @type {Map.<string,Filter>}
65 */ 65 */
66 let exceptions = new Map(); 66 let exceptions = new Map();
67 67
68 /** 68 /**
69 * Returns a list of selectors that apply on each website unconditionally.
70 * @returns {string[]}
71 */
72 function getUnconditionalSelectors()
73 {
74 if (!unconditionalSelectors)
75 unconditionalSelectors = [...filterBySelector.keys()];
76
77 return unconditionalSelectors;
78 }
79
80 /**
69 * Container for element hiding filters 81 * Container for element hiding filters
70 * @class 82 * @class
71 */ 83 */
72 let ElemHide = exports.ElemHide = { 84 let ElemHide = exports.ElemHide = {
73 /** 85 /**
74 * Removes all known filters 86 * Removes all known filters
75 */ 87 */
76 clear() 88 clear()
77 { 89 {
78 for (let collection of [filtersByDomain, filterBySelector, 90 for (let collection of [filtersByDomain, filterBySelector,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 for (let i = list.length - 1; i >= 0; i--) 212 for (let i = list.length - 1; i >= 0; i--)
201 { 213 {
202 if (list[i].isActiveOnDomain(docDomain)) 214 if (list[i].isActiveOnDomain(docDomain))
203 return list[i]; 215 return list[i];
204 } 216 }
205 217
206 return null; 218 return null;
207 }, 219 },
208 220
209 /** 221 /**
210 * Returns a list of selectors that apply on each website unconditionally.
211 * @returns {string[]}
212 */
213 getUnconditionalSelectors()
214 {
215 if (!unconditionalSelectors)
216 unconditionalSelectors = [...filterBySelector.keys()];
217 return unconditionalSelectors.slice();
218 },
219
220 /**
221 * Constant used by getSelectorsForDomain to return all selectors applying to 222 * Constant used by getSelectorsForDomain to return all selectors applying to
222 * a particular hostname. 223 * a particular hostname.
223 * @type {number} 224 * @type {number}
224 * @const 225 * @const
225 */ 226 */
226 ALL_MATCHING: 0, 227 ALL_MATCHING: 0,
227 228
228 /** 229 /**
229 * Constant used by getSelectorsForDomain to exclude selectors which apply to 230 * Constant used by getSelectorsForDomain to exclude selectors which apply to
230 * all websites without exception. 231 * all websites without exception.
(...skipping 17 matching lines...) Expand all
248 * @param {number} [criteria] 249 * @param {number} [criteria]
249 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or 250 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or
250 * ElemHide.SPECIFIC_ONLY. 251 * ElemHide.SPECIFIC_ONLY.
251 * @returns {string[]} 252 * @returns {string[]}
252 * List of selectors. 253 * List of selectors.
253 */ 254 */
254 getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING) 255 getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING)
255 { 256 {
256 let selectors = []; 257 let selectors = [];
257 258
258 if (criteria < ElemHide.NO_UNCONDITIONAL)
259 selectors = this.getUnconditionalSelectors();
260
261 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); 259 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
262 let excluded = new Set(); 260 let excluded = new Set();
263 let currentDomain = domain ? domain.toUpperCase() : ""; 261 let currentDomain = domain ? domain.toUpperCase() : "";
264 262
265 // This code is a performance hot-spot, which is why we've made certain 263 // This code is a performance hot-spot, which is why we've made certain
266 // micro-optimisations. Please be careful before making changes. 264 // micro-optimisations. Please be careful before making changes.
267 while (true) 265 while (true)
268 { 266 {
269 if (specificOnly && currentDomain == "") 267 if (specificOnly && currentDomain == "")
270 break; 268 break;
(...skipping 15 matching lines...) Expand all
286 } 284 }
287 } 285 }
288 286
289 if (currentDomain == "") 287 if (currentDomain == "")
290 break; 288 break;
291 289
292 let nextDot = currentDomain.indexOf("."); 290 let nextDot = currentDomain.indexOf(".");
293 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 291 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
294 } 292 }
295 293
294 if (criteria < ElemHide.NO_UNCONDITIONAL)
295 selectors = getUnconditionalSelectors().concat(selectors);
296
296 return selectors; 297 return selectors;
297 } 298 }
298 }; 299 };
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