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: Clear map Created Dec. 20, 2018, 10:57 a.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._keywordsByFilter.clear(); 188 this._keywordByFilter.clear();
189 this._simpleFiltersByKeyword.clear(); 189 this._simpleFiltersByKeyword.clear();
190 this._complexFiltersByKeyword.clear(); 190 this._complexFiltersByKeyword.clear();
191 this._filterMapsByType.clear(); 191 this._filterMapsByType.clear();
192 } 192 }
193 193
194 /** 194 /**
195 * Adds a filter to the matcher 195 * Adds a filter to the matcher
196 * @param {RegExpFilter} filter 196 * @param {RegExpFilter} filter
197 */ 197 */
198 add(filter) 198 add(filter)
199 { 199 {
200 if (this._keywordsByFilter.has(filter)) 200 if (this._keywordByFilter.has(filter))
201 return; 201 return;
202 202
203 // Look for a suitable keyword 203 // Look for a suitable keyword
204 let keyword = this.findKeyword(filter); 204 let keyword = this.findKeyword(filter);
205 let locationOnly = filter.isLocationOnly(); 205 let locationOnly = filter.isLocationOnly();
206 206
207 addFilterByKeyword(filter, keyword, 207 addFilterByKeyword(filter, keyword,
208 locationOnly ? this._simpleFiltersByKeyword : 208 locationOnly ? this._simpleFiltersByKeyword :
209 this._complexFiltersByKeyword); 209 this._complexFiltersByKeyword);
210 210
211 this._keywordsByFilter.set(filter, keyword); 211 this._keywordByFilter.set(filter, keyword);
212 212
213 if (locationOnly) 213 if (locationOnly)
214 return; 214 return;
215 215
216 for (let type of nonDefaultTypes(filter.contentType)) 216 for (let type of nonDefaultTypes(filter.contentType))
217 { 217 {
218 let map = this._filterMapsByType.get(type); 218 let map = this._filterMapsByType.get(type);
219 if (!map) 219 if (!map)
220 this._filterMapsByType.set(type, map = new Map()); 220 this._filterMapsByType.set(type, map = new Map());
221 221
222 addFilterByKeyword(filter, keyword, map); 222 addFilterByKeyword(filter, keyword, map);
223 } 223 }
224 } 224 }
225 225
226 /** 226 /**
227 * Removes a filter from the matcher 227 * Removes a filter from the matcher
228 * @param {RegExpFilter} filter 228 * @param {RegExpFilter} filter
229 */ 229 */
230 remove(filter) 230 remove(filter)
231 { 231 {
232 let keyword = this._keywordsByFilter.get(filter); 232 let keyword = this._keywordByFilter.get(filter);
233 if (typeof keyword == "undefined") 233 if (typeof keyword == "undefined")
234 return; 234 return;
235 235
236 let locationOnly = filter.isLocationOnly(); 236 let locationOnly = filter.isLocationOnly();
237 237
238 removeFilterByKeyword(filter, keyword, 238 removeFilterByKeyword(filter, keyword,
239 locationOnly ? this._simpleFiltersByKeyword : 239 locationOnly ? this._simpleFiltersByKeyword :
240 this._complexFiltersByKeyword); 240 this._complexFiltersByKeyword);
241 241
242 this._keywordsByFilter.delete(filter); 242 this._keywordByFilter.delete(filter);
243 243
244 if (locationOnly) 244 if (locationOnly)
245 return; 245 return;
246 246
247 for (let type of nonDefaultTypes(filter.contentType)) 247 for (let type of nonDefaultTypes(filter.contentType))
248 { 248 {
249 let map = this._filterMapsByType.get(type); 249 let map = this._filterMapsByType.get(type);
250 if (map) 250 if (map)
251 removeFilterByKeyword(filter, keyword, map); 251 removeFilterByKeyword(filter, keyword, map);
252 } 252 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 exports.CombinedMatcher = CombinedMatcher; 571 exports.CombinedMatcher = CombinedMatcher;
572 572
573 /** 573 /**
574 * Shared {@link CombinedMatcher} instance that should usually be used. 574 * Shared {@link CombinedMatcher} instance that should usually be used.
575 * @type {CombinedMatcher} 575 * @type {CombinedMatcher}
576 */ 576 */
577 let defaultMatcher = new CombinedMatcher(); 577 let defaultMatcher = new CombinedMatcher();
578 578
579 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