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

Delta Between Two Patch Sets: lib/matcher.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Left Patch Set: Addressed Wladimir's comments Created March 8, 2017, 12:28 p.m.
Right Patch Set: Removed unused imports Created March 15, 2017, 3: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 | « lib/filterStorage.js ('k') | lib/notification.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 238
239 return null; 239 return null;
240 } 240 }
241 }; 241 };
242 242
243 /** 243 /**
244 * Combines a matcher for blocking and exception rules, automatically sorts 244 * Combines a matcher for blocking and exception rules, automatically sorts
245 * rules into two Matcher instances. 245 * rules into two Matcher instances.
246 * @constructor 246 * @constructor
247 * @augments Matcher
247 */ 248 */
248 function CombinedMatcher() 249 function CombinedMatcher()
249 { 250 {
250 this.blacklist = new Matcher(); 251 this.blacklist = new Matcher();
251 this.whitelist = new Matcher(); 252 this.whitelist = new Matcher();
252 this.resultCache = Object.create(null); 253 this.resultCache = Object.create(null);
253 } 254 }
254 exports.CombinedMatcher = CombinedMatcher; 255 exports.CombinedMatcher = CombinedMatcher;
255 256
256 /** 257 /**
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ); 381 );
381 if (matcher.hasFilter(filter)) 382 if (matcher.hasFilter(filter))
382 return !matcher.getKeywordForFilter(filter); 383 return !matcher.getKeywordForFilter(filter);
383 return !matcher.findKeyword(filter); 384 return !matcher.findKeyword(filter);
384 }, 385 },
385 386
386 /** 387 /**
387 * Optimized filter matching testing both whitelist and blacklist matchers 388 * Optimized filter matching testing both whitelist and blacklist matchers
388 * simultaneously. For parameters see Matcher.matchesAny(). 389 * simultaneously. For parameters see Matcher.matchesAny().
389 * @see Matcher#matchesAny 390 * @see Matcher#matchesAny
391 * @inheritdoc
390 */ 392 */
391 matchesAnyInternal(location, typeMask, docDomain, thirdParty, sitekey, 393 matchesAnyInternal(location, typeMask, docDomain, thirdParty, sitekey,
392 specificOnly) 394 specificOnly)
393 { 395 {
394 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); 396 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
395 if (candidates === null) 397 if (candidates === null)
396 candidates = []; 398 candidates = [];
397 candidates.push(""); 399 candidates.push("");
398 400
399 let blacklistHit = null; 401 let blacklistHit = null;
(...skipping 14 matching lines...) Expand all
414 substr, location, typeMask, docDomain, thirdParty, sitekey, 416 substr, location, typeMask, docDomain, thirdParty, sitekey,
415 specificOnly 417 specificOnly
416 ); 418 );
417 } 419 }
418 } 420 }
419 return blacklistHit; 421 return blacklistHit;
420 }, 422 },
421 423
422 /** 424 /**
423 * @see Matcher#matchesAny 425 * @see Matcher#matchesAny
426 * @inheritdoc
424 */ 427 */
425 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly) 428 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly)
426 { 429 {
427 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty + 430 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty +
428 " " + sitekey + " " + specificOnly; 431 " " + sitekey + " " + specificOnly;
429 if (key in this.resultCache) 432 if (key in this.resultCache)
430 return this.resultCache[key]; 433 return this.resultCache[key];
431 434
432 let result = this.matchesAnyInternal(location, typeMask, docDomain, 435 let result = this.matchesAnyInternal(location, typeMask, docDomain,
433 thirdParty, sitekey, specificOnly); 436 thirdParty, sitekey, specificOnly);
434 437
435 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) 438 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries)
436 { 439 {
437 this.resultCache = Object.create(null); 440 this.resultCache = Object.create(null);
438 this.cacheEntries = 0; 441 this.cacheEntries = 0;
439 } 442 }
440 443
441 this.resultCache[key] = result; 444 this.resultCache[key] = result;
442 this.cacheEntries++; 445 this.cacheEntries++;
443 446
444 return result; 447 return result;
445 } 448 }
446 }; 449 };
447 450
448 /** 451 /**
449 * Shared CombinedMatcher instance that should usually be used. 452 * Shared CombinedMatcher instance that should usually be used.
450 * @type {CombinedMatcher} 453 * @type {CombinedMatcher}
451 */ 454 */
452 exports.defaultMatcher = new CombinedMatcher(); 455 exports.defaultMatcher = new CombinedMatcher();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld