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: Roll back generics overkill Created May 14, 2018, 1:18 a.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 {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 for (let [domain, include] of filter.domains || []) 48 for (let [domain, include] of filter.domains || [])
49 { 49 {
50 if (domain != "") 50 if (domain != "")
51 yield [domain, include, filtersByDomain.get(domain)]; 51 yield [domain, include, filtersByDomain.get(domain)];
52 }
53 }
54
55 /**
56 * Yields subdomains of a domain
57 * @param {string} domain
58 * @yields {string}
59 */
60 function* subdomains(domain)
61 {
62 for (let [, subdomain] of
63 regExpIt(/([^|]*)\|/g, domain.replace(/([^.]+\.)/g, "$'|")))
64 {
65 yield subdomain;
66 } 52 }
67 } 53 }
68 54
69 /** 55 /**
70 * 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
71 * filter should be included on its corresponding domain 57 * filter should be included on its corresponding domain
72 * @param {string} domain 58 * @param {string} domain
73 * @yields {Array.<ElemHideEmulationFilter,boolean>} 59 * @yields {Array.<ElemHideEmulationFilter,boolean>}
74 */ 60 */
75 function* filtersForDomain(domain) 61 function* filtersForDomain(domain)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 !ElemHide.getException(filter, domain)) 142 !ElemHide.getException(filter, domain))
157 { 143 {
158 result.push(filter); 144 result.push(filter);
159 } 145 }
160 } 146 }
161 147
162 return result; 148 return result;
163 } 149 }
164 }; 150 };
165 exports.ElemHideEmulation = ElemHideEmulation; 151 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld