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

Side by Side Diff: lib/matcher.js

Issue 29896562: Issue 7003 - Look up whitelist filter only if URL is blocked (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 30, 2018, 8:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 * @inheritdoc 360 * @inheritdoc
361 */ 361 */
362 matchesAnyInternal(location, typeMask, docDomain, thirdParty, sitekey, 362 matchesAnyInternal(location, typeMask, docDomain, thirdParty, sitekey,
363 specificOnly) 363 specificOnly)
364 { 364 {
365 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); 365 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
366 if (candidates === null) 366 if (candidates === null)
367 candidates = []; 367 candidates = [];
368 candidates.push(""); 368 candidates.push("");
369 369
370 let whitelistHit = null;
370 let blacklistHit = null; 371 let blacklistHit = null;
372
371 for (let i = 0, l = candidates.length; i < l; i++) 373 for (let i = 0, l = candidates.length; i < l; i++)
Sebastian Noack 2018/09/30 13:39:23 Any reason to not use for..of here?
Manish Jethani 2018/10/21 13:57:03 for..of is quite a bit slower in this case.
372 { 374 {
373 let substr = candidates[i]; 375 let substr = candidates[i];
374 let result = this.whitelist._checkEntryMatch( 376 blacklistHit = this.blacklist._checkEntryMatch(
375 substr, location, typeMask, docDomain, thirdParty, sitekey 377 substr, location, typeMask, docDomain, thirdParty, sitekey,
378 specificOnly
376 ); 379 );
377 if (result) 380 if (blacklistHit)
378 return result; 381 break;
379 if (blacklistHit === null) 382 }
383
384 if (blacklistHit)
385 {
386 for (let i = 0, l = candidates.length; i < l; i++)
380 { 387 {
381 blacklistHit = this.blacklist._checkEntryMatch( 388 let substr = candidates[i];
382 substr, location, typeMask, docDomain, thirdParty, sitekey, 389 whitelistHit = this.whitelist._checkEntryMatch(
383 specificOnly 390 substr, location, typeMask, docDomain, thirdParty, sitekey
384 ); 391 );
392 if (whitelistHit)
393 break;
385 } 394 }
386 } 395 }
387 return blacklistHit; 396
397 return whitelistHit || blacklistHit;
388 } 398 }
389 399
390 /** 400 /**
391 * @see Matcher#matchesAny 401 * @see Matcher#matchesAny
392 * @inheritdoc 402 * @inheritdoc
393 */ 403 */
394 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly) 404 matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly)
395 { 405 {
396 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty + 406 let key = location + " " + typeMask + " " + docDomain + " " + thirdParty +
397 " " + sitekey + " " + specificOnly; 407 " " + sitekey + " " + specificOnly;
(...skipping 16 matching lines...) Expand all
414 424
415 exports.CombinedMatcher = CombinedMatcher; 425 exports.CombinedMatcher = CombinedMatcher;
416 426
417 /** 427 /**
418 * Shared {@link CombinedMatcher} instance that should usually be used. 428 * Shared {@link CombinedMatcher} instance that should usually be used.
419 * @type {CombinedMatcher} 429 * @type {CombinedMatcher}
420 */ 430 */
421 let defaultMatcher = new CombinedMatcher(); 431 let defaultMatcher = new CombinedMatcher();
422 432
423 exports.defaultMatcher = defaultMatcher; 433 exports.defaultMatcher = defaultMatcher;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld