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

Side by Side Diff: lib/elemHide.js

Issue 29773570: Issue 6652 - Implement fast selector lookups for unknown domains (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Inline doesFilterApply Created May 15, 2018, 3:37 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 continue; 111 continue;
112 112
113 let filters = filtersByDomain.get(domain); 113 let filters = filtersByDomain.get(domain);
114 if (!filters) 114 if (!filters)
115 filtersByDomain.set(domain, filters = new Map()); 115 filtersByDomain.set(domain, filters = new Map());
116 filters.set(filter, isIncluded); 116 filters.set(filter, isIncluded);
117 } 117 }
118 } 118 }
119 } 119 }
120 120
121
122 /**
123 * Checks whether a filter applies on a domain
124 * @param {Filter} filter
125 * @param {string} [domain]
126 * @param {Set.<Filter>} excludeSet
127 * @returns {boolean}
128 */
129 function doesFilterApply(filter, domain, excludeSet)
130 {
131 return (excludeSet.size == 0 || !excludeSet.has(filter)) &&
132 !exports.ElemHide.getException(filter, domain);
133 }
134
135 /** 121 /**
136 * Returns a list of domain-specific filters matching a domain 122 * Returns a list of domain-specific filters matching a domain
137 * @param {string} [domain] 123 * @param {string} [domain]
138 * @returns {Array.<{domain: string, filters: ?Map.<Filter,boolean>}>} 124 * @returns {Array.<{domain: string, filters: ?Map.<Filter,boolean>}>}
139 */ 125 */
140 function getSpecificFiltersForDomain(domain) 126 function getSpecificFiltersForDomain(domain)
141 { 127 {
142 let filtersList = []; 128 let filtersList = [];
143 129
144 if (domain) 130 if (domain)
(...skipping 27 matching lines...) Expand all
172 // This code is a performance hot-spot, which is why we've made certain 158 // This code is a performance hot-spot, which is why we've made certain
173 // micro-optimisations. Please be careful before making changes. 159 // micro-optimisations. Please be careful before making changes.
174 for (let i = 0; i < filtersList.length; i++) 160 for (let i = 0; i < filtersList.length; i++)
175 { 161 {
176 let {filters} = filtersList[i]; 162 let {filters} = filtersList[i];
177 if (filters) 163 if (filters)
178 { 164 {
179 for (let [filter, isIncluded] of filters) 165 for (let [filter, isIncluded] of filters)
180 { 166 {
181 if (!isIncluded) 167 if (!isIncluded)
168 {
182 excludeSet.add(filter); 169 excludeSet.add(filter);
183 else if (doesFilterApply(filter, domain, excludeSet)) 170 }
171 else if ((excludeSet.size == 0 || !excludeSet.has(filter)) &&
172 !exports.ElemHide.getException(filter, domain))
173 {
184 matches.push(filter.selector); 174 matches.push(filter.selector);
175 }
185 } 176 }
186 } 177 }
187 } 178 }
188 179
189 return matches; 180 return matches;
190 } 181 }
191 182
192 /** 183 /**
193 * Returns a list of selectors that apply on a domain 184 * Returns a list of selectors that apply on a domain
194 * @param {string} [domain] 185 * @param {string} [domain]
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 getSelectorsForDomain(domain, specificOnly = false) 433 getSelectorsForDomain(domain, specificOnly = false)
443 { 434 {
444 let selectors = getConditionalSelectorsForDomain(domain, specificOnly); 435 let selectors = getConditionalSelectorsForDomain(domain, specificOnly);
445 436
446 if (!specificOnly) 437 if (!specificOnly)
447 selectors = getUnconditionalSelectors().concat(selectors); 438 selectors = getUnconditionalSelectors().concat(selectors);
448 439
449 return selectors; 440 return selectors;
450 } 441 }
451 }; 442 };
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