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: Fix JSDoc yield type Created May 13, 2018, 8:48 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,Map.<ElemHideEmulationFilter,boolean>>} 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 /** 39 /**
40 * Yields the domains associated with a filter, along with whether the filter 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 41 * should be included on the domain and the set of filters associated with the
42 * domain 42 * domain
43 * @param {ElemHideEmulationFilter} filter 43 * @param {ElemHideEmulationFilter} filter
44 * @yields {Array.<string,boolean,?Set.<ElemHideEmulationFilter>>} 44 * @yields {Array.<string,boolean,?Set.<ElemHideEmulationFilter>>}
45 */ 45 */
46 function* filterDomains(filter) 46 function* filterDomains(filter)
47 { 47 {
48 yield* mapIt(filterIt(filter.domains || [], ([domain]) => domain != ""), 48 for (let [domain, include] of filter.domains || [])
49 ([domain, include]) => [domain, include, 49 {
50 filtersByDomain.get(domain)]); 50 if (domain != "")
51 } 51 yield [domain, include, filtersByDomain.get(domain)];
52 52 }
53 /**
54 * Yields subdomains of a domain
55 * @param {string} domain
56 * @yields {string}
57 */
58 function* subdomains(domain)
59 {
60 yield* mapIt(regExpIt(/([^|]*)\|/g, domain.replace(/([^.]+\.)/g, "$'|")),
61 ([, subdomain]) => subdomain);
62 } 53 }
63 54
64 /** 55 /**
65 * Yields the filters for a domain and its subdomains, along with whether the 56 * Yields the filters for a domain and its subdomains, along with whether the
66 * filter should be included on its corresponding domain 57 * filter should be included on its corresponding domain
67 * @param {string} domain 58 * @param {string} domain
68 * @yields {Array.<ElemHideEmulationFilter,boolean>} 59 * @yields {Array.<ElemHideEmulationFilter,boolean>}
69 */ 60 */
70 function* filtersForDomain(domain) 61 function* filtersForDomain(domain)
71 { 62 {
72 yield* filtersByDomain.get(domain) || []; 63 yield* filtersByDomain.get(domain) || [];
73 64
74 yield* flattenIt(mapIt(subdomains(domain), 65 for (let subdomain of subdomains(domain))
75 subdomain => filtersByDomain.get(subdomain) || [])); 66 yield* filtersByDomain.get(subdomain) || [];
76 } 67 }
77 68
78 /** 69 /**
79 * Container for element hiding emulation filters 70 * Container for element hiding emulation filters
80 * @class 71 * @class
81 */ 72 */
82 let ElemHideEmulation = { 73 let ElemHideEmulation = {
83 /** 74 /**
84 * Removes all known filters 75 * Removes all known filters
85 */ 76 */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 !ElemHide.getException(filter, domain)) 142 !ElemHide.getException(filter, domain))
152 { 143 {
153 result.push(filter); 144 result.push(filter);
154 } 145 }
155 } 146 }
156 147
157 return result; 148 return result;
158 } 149 }
159 }; 150 };
160 exports.ElemHideEmulation = ElemHideEmulation; 151 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld