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 on patch #29778572 Created May 11, 2018, 12:23 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 | 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 /** 88 /**
89 * Returns a list of selectors that apply on each website unconditionally. 89 * Returns a list of selectors that apply on each website unconditionally.
90 * @returns {string[]} 90 * @returns {string[]}
91 */ 91 */
92 function getUnconditionalSelectors() 92 function getUnconditionalSelectors()
93 { 93 {
94 if (!unconditionalSelectors) 94 if (!unconditionalSelectors)
95 unconditionalSelectors = [...filterBySelector.keys()]; 95 unconditionalSelectors = [...filterBySelector.keys()];
96 96
97 return unconditionalSelectors.slice(); 97 return unconditionalSelectors;
98 } 98 }
99 99
100 /** 100 /**
101 * Container for element hiding filters 101 * Container for element hiding filters
102 * @class 102 * @class
103 */ 103 */
104 let ElemHide = exports.ElemHide = { 104 let ElemHide = exports.ElemHide = {
105 /** 105 /**
106 * Removes all known filters 106 * Removes all known filters
107 */ 107 */
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 * @param {number} [criteria] 253 * @param {number} [criteria]
254 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or 254 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or
255 * ElemHide.SPECIFIC_ONLY. 255 * ElemHide.SPECIFIC_ONLY.
256 * @returns {string[]} 256 * @returns {string[]}
257 * List of selectors. 257 * List of selectors.
258 */ 258 */
259 getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING) 259 getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING)
260 { 260 {
261 let selectors = []; 261 let selectors = [];
262 262
263 if (criteria < ElemHide.NO_UNCONDITIONAL)
264 selectors = getUnconditionalSelectors();
265
266 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); 263 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
267 let excluded = new Set(); 264 let excluded = new Set();
268 let currentDomain = domain ? domain.toUpperCase() : ""; 265 let currentDomain = domain ? domain.toUpperCase() : "";
269 266
270 // This code is a performance hot-spot, which is why we've made certain 267 // This code is a performance hot-spot, which is why we've made certain
271 // micro-optimisations. Please be careful before making changes. 268 // micro-optimisations. Please be careful before making changes.
272 while (true) 269 while (true)
273 { 270 {
274 if (specificOnly && currentDomain == "") 271 if (specificOnly && currentDomain == "")
275 break; 272 break;
(...skipping 15 matching lines...) Expand all
291 } 288 }
292 } 289 }
293 290
294 if (currentDomain == "") 291 if (currentDomain == "")
295 break; 292 break;
296 293
297 let nextDot = currentDomain.indexOf("."); 294 let nextDot = currentDomain.indexOf(".");
298 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 295 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
299 } 296 }
300 297
298 if (criteria < ElemHide.NO_UNCONDITIONAL)
299 selectors = getUnconditionalSelectors().concat(selectors);
300
301 return selectors; 301 return selectors;
302 } 302 }
303 }; 303 };
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