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

Delta Between Two Patch Sets: lib/elemHideEmulation.js

Issue 29780560: Issue 6665 - Optimize element hiding emulation filter lookups (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Separate out subdomains generator function Created May 13, 2018, 7:41 p.m.
Right Patch Set: Use String.indexOf for subdomains Created May 14, 2018, 2:22 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/common.js ('k') | test/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 emulation implementation. 21 * @fileOverview Element hiding emulation implementation.
22 */ 22 */
23 23
24 const {ElemHide} = require("./elemHide"); 24 const {ElemHide} = require("./elemHide");
25 const {filterIt, mapIt, flattenIt, regExpIt} = require("./coreUtils"); 25 const {subdomains} = require("./common");
26 26
27 /** 27 /**
28 * Map of element hiding emulation filters by domain 28 * Map of element hiding emulation filters by domain
29 * @type {Map.<string,Set.<ElemHideEmulationFilter>>} 29 * @type {Map.<string,Map.<ElemHideEmulationFilter,boolean>>}
30 */ 30 */
31 let filtersByDomain = new Map(); 31 let filtersByDomain = new Map();
32 32
33 /** 33 /**
34 * Set containing known element hiding emulation filters 34 * Set containing known element hiding emulation filters
35 * @type {Set.<ElemHideEmulation>} 35 * @type {Set.<ElemHideEmulation>}
36 */ 36 */
37 let knownFilters = new Set(); 37 let knownFilters = new Set();
38 38
39 /**
40 * Yields the domains associated with a filter, along with whether the filter
41 * should be included on the domain and the set of filters associated with the
42 * domain
43 * @param {ElemHideEmulationFilter} filter
44 * @yields {Array.<string,boolean,?Set.<ElemHideEmulationFilter>>}
45 */
39 function* filterDomains(filter) 46 function* filterDomains(filter)
40 { 47 {
41 yield* mapIt(filterIt(filter.domains || [], ([domain]) => domain != ""), 48 for (let [domain, include] of filter.domains || [])
42 ([domain, include]) => [domain, include, 49 {
43 filtersByDomain.get(domain)]); 50 if (domain != "")
51 yield [domain, include, filtersByDomain.get(domain)];
52 }
44 } 53 }
45 54
46 function* subdomains(domain) 55 /**
47 { 56 * Yields the filters for a domain and its subdomains, along with whether the
48 yield* mapIt(regExpIt(/([^|]*)\|/g, domain.replace(/([^.]+\.)/g, "$'|")), 57 * filter should be included on its corresponding domain
49 ([, subdomain]) => subdomain); 58 * @param {string} domain
50 } 59 * @yields {Array.<ElemHideEmulationFilter,boolean>}
51 60 */
52 function* filtersForDomain(domain) 61 function* filtersForDomain(domain)
53 { 62 {
54 yield* filtersByDomain.get(domain) || []; 63 yield* filtersByDomain.get(domain) || [];
55 64
56 yield* flattenIt(mapIt(subdomains(domain), 65 for (let subdomain of subdomains(domain))
57 subdomain => filtersByDomain.get(subdomain) || [])); 66 yield* filtersByDomain.get(subdomain) || [];
58 } 67 }
59 68
60 /** 69 /**
61 * Container for element hiding emulation filters 70 * Container for element hiding emulation filters
62 * @class 71 * @class
63 */ 72 */
64 let ElemHideEmulation = { 73 let ElemHideEmulation = {
65 /** 74 /**
66 * Removes all known filters 75 * Removes all known filters
67 */ 76 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 124
116 /** 125 /**
117 * Returns a list of all rules active on a particular domain 126 * Returns a list of all rules active on a particular domain
118 * @param {string} domain 127 * @param {string} domain
119 * @return {ElemHideEmulationFilter[]} 128 * @return {ElemHideEmulationFilter[]}
120 */ 129 */
121 getRulesForDomain(domain) 130 getRulesForDomain(domain)
122 { 131 {
123 let result = []; 132 let result = [];
124 133
125 let excludeSet = new Set(); 134 let excludeSet = new Set();
Manish Jethani 2018/05/13 20:39:48 The logic here is similar to lib/elemHide.js Even
126 for (let [filter, include] of filtersForDomain(domain.toUpperCase())) 135 for (let [filter, include] of filtersForDomain(domain.toUpperCase()))
127 { 136 {
128 if (!include) 137 if (!include)
129 { 138 {
130 excludeSet.add(filter); 139 excludeSet.add(filter);
131 } 140 }
132 else if ((excludeSet.size == 0 || !excludeSet.has(filter)) && 141 else if ((excludeSet.size == 0 || !excludeSet.has(filter)) &&
133 !ElemHide.getException(filter, domain)) 142 !ElemHide.getException(filter, domain))
134 { 143 {
135 result.push(filter); 144 result.push(filter);
136 } 145 }
137 } 146 }
138 147
139 return result; 148 return result;
140 } 149 }
141 }; 150 };
142 exports.ElemHideEmulation = ElemHideEmulation; 151 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld