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

Side by Side Diff: lib/elemHide.js

Issue 29999569: Noissue - Use suffixes function (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 5, 2019, 3:19 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 | « lib/domain.js ('k') | lib/filterClasses.js » ('j') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Element hiding implementation. 21 * @fileOverview Element hiding implementation.
22 */ 22 */
23 23
24 const {ElemHideExceptions} = require("./elemHideExceptions"); 24 const {ElemHideExceptions} = require("./elemHideExceptions");
25 const {filterNotifier} = require("./filterNotifier"); 25 const {filterNotifier} = require("./filterNotifier");
26 const {suffixes} = require("./domain");
26 27
27 /** 28 /**
28 * The maximum number of selectors in a CSS rule. This is used by 29 * The maximum number of selectors in a CSS rule. This is used by
29 * <code>{@link createStyleSheet}</code> to split up a long list of selectors 30 * <code>{@link createStyleSheet}</code> to split up a long list of selectors
30 * into multiple rules. 31 * into multiple rules.
31 * @const {number} 32 * @const {number}
32 * @default 33 * @default
33 */ 34 */
34 const selectorGroupSize = 1024; 35 const selectorGroupSize = 1024;
35 36
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 * @param {boolean} specificOnly Whether selectors from generic filters should 163 * @param {boolean} specificOnly Whether selectors from generic filters should
163 * be included. 164 * be included.
164 * 165 *
165 * @returns {Array.<string>} The list of selectors. 166 * @returns {Array.<string>} The list of selectors.
166 */ 167 */
167 function getConditionalSelectors(domain, specificOnly) 168 function getConditionalSelectors(domain, specificOnly)
168 { 169 {
169 let selectors = []; 170 let selectors = [];
170 171
171 let excluded = new Set(); 172 let excluded = new Set();
172 let currentDomain = domain;
173 173
174 // This code is a performance hot-spot, which is why we've made certain 174 // This code is a performance hot-spot, which is why we've made certain
175 // micro-optimisations. Please be careful before making changes. 175 // micro-optimisations. Please be careful before making changes.
176 while (true) 176 for (let currentDomain of suffixes(domain, !specificOnly))
hub 2019/02/06 12:55:05 I assume that this change doesn't cause a performa
Manish Jethani 2019/02/06 13:13:31 This is no longer a hot spot and in fact this comm
Manish Jethani 2019/02/06 13:17:06 Done.
177 { 177 {
178 if (specificOnly && currentDomain == "")
179 break;
180
181 let filters = filtersByDomain.get(currentDomain); 178 let filters = filtersByDomain.get(currentDomain);
182 if (filters) 179 if (filters)
183 { 180 {
184 for (let [filter, isIncluded] of filters) 181 for (let [filter, isIncluded] of filters)
185 { 182 {
186 if (!isIncluded) 183 if (!isIncluded)
187 { 184 {
188 excluded.add(filter); 185 excluded.add(filter);
189 } 186 }
190 else 187 else
191 { 188 {
192 let {selector} = filter; 189 let {selector} = filter;
193 if ((excluded.size == 0 || !excluded.has(filter)) && 190 if ((excluded.size == 0 || !excluded.has(filter)) &&
194 !ElemHideExceptions.getException(selector, domain)) 191 !ElemHideExceptions.getException(selector, domain))
195 { 192 {
196 selectors.push(selector); 193 selectors.push(selector);
197 } 194 }
198 } 195 }
199 } 196 }
200 } 197 }
201
202 if (currentDomain == "")
203 break;
204
205 let nextDot = currentDomain.indexOf(".");
206 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
207 } 198 }
208 199
209 return selectors; 200 return selectors;
210 } 201 }
211 202
212 /** 203 /**
213 * Returns the default style sheet that applies on all domains. 204 * Returns the default style sheet that applies on all domains.
214 * @returns {string} 205 * @returns {string}
215 */ 206 */
216 function getDefaultStyleSheet() 207 function getDefaultStyleSheet()
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 { 508 {
518 let styleSheet = ""; 509 let styleSheet = "";
519 510
520 for (let selectorGroup of splitSelectors(selectors)) 511 for (let selectorGroup of splitSelectors(selectors))
521 styleSheet += createRule(selectorGroup); 512 styleSheet += createRule(selectorGroup);
522 513
523 return styleSheet; 514 return styleSheet;
524 } 515 }
525 516
526 exports.createStyleSheet = createStyleSheet; 517 exports.createStyleSheet = createStyleSheet;
OLDNEW
« no previous file with comments | « lib/domain.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld