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

Delta Between Two Patch Sets: lib/matcher.js

Issue 29965589: Issue 7181 - Keep a keyword-by-filter map after all (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Dec. 19, 2018, 6:24 p.m.
Right Patch Set: Rename to _keywordByFilter Created Dec. 20, 2018, 11 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 | « no previous file | test/matcher.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
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 */ 148 */
149 class Matcher 149 class Matcher
150 { 150 {
151 constructor() 151 constructor()
152 { 152 {
153 /** 153 /**
154 * Lookup table for keywords by their associated filter 154 * Lookup table for keywords by their associated filter
155 * @type {Map.<RegExpFilter,string>} 155 * @type {Map.<RegExpFilter,string>}
156 * @private 156 * @private
157 */ 157 */
158 this._keywordsByFilter = new Map(); 158 this._keywordByFilter = new Map();
159 159
160 /** 160 /**
161 * Lookup table for simple filters by their associated keyword 161 * Lookup table for simple filters by their associated keyword
162 * @type {Map.<string,(RegExpFilter|Set.<RegExpFilter>)>} 162 * @type {Map.<string,(RegExpFilter|Set.<RegExpFilter>)>}
163 * @private 163 * @private
164 */ 164 */
165 this._simpleFiltersByKeyword = new Map(); 165 this._simpleFiltersByKeyword = new Map();
166 166
167 /** 167 /**
168 * Lookup table for complex filters by their associated keyword 168 * Lookup table for complex filters by their associated keyword
169 * @type {Map.<string,(RegExpFilter|Set.<RegExpFilter>)>} 169 * @type {Map.<string,(RegExpFilter|Set.<RegExpFilter>)>}
170 * @private 170 * @private
171 */ 171 */
172 this._complexFiltersByKeyword = new Map(); 172 this._complexFiltersByKeyword = new Map();
173 173
174 /** 174 /**
175 * Lookup table of type-specific lookup tables for complex filters by their 175 * Lookup table of type-specific lookup tables for complex filters by their
176 * associated keyword 176 * associated keyword
177 * @type {Map.<string,Map.<string,(RegExpFilter|Set.<RegExpFilter>)>>} 177 * @type {Map.<string,Map.<string,(RegExpFilter|Set.<RegExpFilter>)>>}
178 * @private 178 * @private
179 */ 179 */
180 this._filterMapsByType = new Map(); 180 this._filterMapsByType = new Map();
181 } 181 }
182 182
183 /** 183 /**
184 * Removes all known filters 184 * Removes all known filters
185 */ 185 */
186 clear() 186 clear()
187 { 187 {
188 this._keywordByFilter.clear();
188 this._simpleFiltersByKeyword.clear(); 189 this._simpleFiltersByKeyword.clear();
189 this._complexFiltersByKeyword.clear(); 190 this._complexFiltersByKeyword.clear();
190 this._filterMapsByType.clear(); 191 this._filterMapsByType.clear();
191 } 192 }
192 193
193 /** 194 /**
194 * Adds a filter to the matcher 195 * Adds a filter to the matcher
195 * @param {RegExpFilter} filter 196 * @param {RegExpFilter} filter
196 */ 197 */
197 add(filter) 198 add(filter)
198 { 199 {
199 if (this._keywordsByFilter.has(filter)) 200 if (this._keywordByFilter.has(filter))
200 return; 201 return;
201 202
202 // Look for a suitable keyword 203 // Look for a suitable keyword
203 let keyword = this.findKeyword(filter); 204 let keyword = this.findKeyword(filter);
204 let locationOnly = filter.isLocationOnly(); 205 let locationOnly = filter.isLocationOnly();
205 206
206 addFilterByKeyword(filter, keyword, 207 addFilterByKeyword(filter, keyword,
207 locationOnly ? this._simpleFiltersByKeyword : 208 locationOnly ? this._simpleFiltersByKeyword :
208 this._complexFiltersByKeyword); 209 this._complexFiltersByKeyword);
209 210
210 this._keywordsByFilter.set(filter, keyword); 211 this._keywordByFilter.set(filter, keyword);
211 212
212 if (locationOnly) 213 if (locationOnly)
213 return; 214 return;
214 215
215 for (let type of nonDefaultTypes(filter.contentType)) 216 for (let type of nonDefaultTypes(filter.contentType))
216 { 217 {
217 let map = this._filterMapsByType.get(type); 218 let map = this._filterMapsByType.get(type);
218 if (!map) 219 if (!map)
219 this._filterMapsByType.set(type, map = new Map()); 220 this._filterMapsByType.set(type, map = new Map());
220 221
221 addFilterByKeyword(filter, keyword, map); 222 addFilterByKeyword(filter, keyword, map);
222 } 223 }
223 } 224 }
224 225
225 /** 226 /**
226 * Removes a filter from the matcher 227 * Removes a filter from the matcher
227 * @param {RegExpFilter} filter 228 * @param {RegExpFilter} filter
228 */ 229 */
229 remove(filter) 230 remove(filter)
230 { 231 {
231 let keyword = this._keywordsByFilter.get(filter); 232 let keyword = this._keywordByFilter.get(filter);
232 if (typeof keyword == "undefined") 233 if (typeof keyword == "undefined")
233 return; 234 return;
234 235
235 let locationOnly = filter.isLocationOnly(); 236 let locationOnly = filter.isLocationOnly();
236 237
237 removeFilterByKeyword(filter, keyword, 238 removeFilterByKeyword(filter, keyword,
238 locationOnly ? this._simpleFiltersByKeyword : 239 locationOnly ? this._simpleFiltersByKeyword :
239 this._complexFiltersByKeyword); 240 this._complexFiltersByKeyword);
240 241
241 this._keywordsByFilter.delete(filter); 242 this._keywordByFilter.delete(filter);
242 243
243 if (locationOnly) 244 if (locationOnly)
244 return; 245 return;
245 246
246 for (let type of nonDefaultTypes(filter.contentType)) 247 for (let type of nonDefaultTypes(filter.contentType))
247 { 248 {
248 let map = this._filterMapsByType.get(type); 249 let map = this._filterMapsByType.get(type);
249 if (map) 250 if (map)
250 removeFilterByKeyword(filter, keyword, map); 251 removeFilterByKeyword(filter, keyword, map);
251 } 252 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 570
570 exports.CombinedMatcher = CombinedMatcher; 571 exports.CombinedMatcher = CombinedMatcher;
571 572
572 /** 573 /**
573 * Shared {@link CombinedMatcher} instance that should usually be used. 574 * Shared {@link CombinedMatcher} instance that should usually be used.
574 * @type {CombinedMatcher} 575 * @type {CombinedMatcher}
575 */ 576 */
576 let defaultMatcher = new CombinedMatcher(); 577 let defaultMatcher = new CombinedMatcher();
577 578
578 exports.defaultMatcher = defaultMatcher; 579 exports.defaultMatcher = defaultMatcher;
LEFTRIGHT
« no previous file | test/matcher.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld