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

Side by Side Diff: lib/matcher.js

Issue 30018555: Issue 7311 - Split _checkEntryMatchByDomain() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Avoid unnecessary call Created Feb. 26, 2019, 10:12 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 (count == resultCount && candidate.length > resultLength)) 415 (count == resultCount && candidate.length > resultLength))
416 { 416 {
417 result = candidate; 417 result = candidate;
418 resultCount = count; 418 resultCount = count;
419 resultLength = candidate.length; 419 resultLength = candidate.length;
420 } 420 }
421 } 421 }
422 return result; 422 return result;
423 } 423 }
424 424
425 _matchFilterWithoutDomain(filter, location, typeMask, thirdParty, sitekey,
426 collection)
427 {
428 if (filter.matchesWithoutDomain(location, typeMask, thirdParty, sitekey))
429 {
430 if (!collection)
431 return filter;
432
433 collection.push(filter);
434 }
435
436 return null;
437 }
438
439 _matchFiltersByDomain(filtersByDomain, location, typeMask, docDomain,
440 thirdParty, sitekey, specificOnly, collection)
441 {
442 let excluded = new Set();
443
444 for (let suffix of domainSuffixes(docDomain ?
445 normalizeHostname(docDomain) : "",
446 !specificOnly))
447 {
448 let filters = filtersByDomain.get(suffix);
449 if (filters)
450 {
451 for (let [filter, include] of filters.entries())
452 {
453 if (!include)
454 {
455 excluded.add(filter);
456 }
457 else if ((excluded.size == 0 || !excluded.has(filter)) &&
458 filter.matchesWithoutDomain(location, typeMask, thirdParty,
459 sitekey, collection))
460 {
461 return filter;
462 }
463 }
464 }
465 }
466
467 return null;
468 }
469
425 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty, 470 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty,
426 sitekey, specificOnly, collection) 471 sitekey, specificOnly, collection)
427 { 472 {
428 let filters = this._simpleFiltersByKeyword.get(keyword); 473 let filters = this._simpleFiltersByKeyword.get(keyword);
429 if (filters) 474 if (filters)
430 { 475 {
431 let lowerCaseLocation = location.toLowerCase(); 476 let lowerCaseLocation = location.toLowerCase();
432 477
433 for (let filter of filters) 478 for (let filter of filters)
434 { 479 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 522
478 return null; 523 return null;
479 } 524 }
480 525
481 _checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty, 526 _checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty,
482 sitekey, specificOnly, collection) 527 sitekey, specificOnly, collection)
483 { 528 {
484 let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword); 529 let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword);
485 if (filtersByDomain) 530 if (filtersByDomain)
486 { 531 {
532 if (filtersByDomain instanceof Map)
533 {
534 return this._matchFiltersByDomain(filtersByDomain, location, typeMask,
535 docDomain, thirdParty, sitekey,
536 specificOnly, collection);
537 }
538
487 // Because of the memory optimization in the add function, most of the 539 // Because of the memory optimization in the add function, most of the
488 // time this will be a filter rather than a map. 540 // time this will be a filter rather than a map.
489 if (!(filtersByDomain instanceof Map)) 541 return this._matchFilterWithoutDomain(filtersByDomain, location,
490 { 542 typeMask, thirdParty, sitekey,
491 if (filtersByDomain.matchesWithoutDomain(location, typeMask, 543 collection);
492 thirdParty, sitekey))
493 {
494 if (!collection)
495 return filtersByDomain;
496
497 collection.push(filtersByDomain);
498 }
499
500 return null;
501 }
502
503 let excluded = new Set();
504
505 for (let suffix of domainSuffixes(docDomain ?
506 normalizeHostname(docDomain) : "",
507 !specificOnly))
508 {
509 let filters = filtersByDomain.get(suffix);
510 if (filters)
511 {
512 for (let [filter, include] of filters.entries())
513 {
514 if (!include)
515 {
516 excluded.add(filter);
517 }
518 else if ((excluded.size == 0 || !excluded.has(filter)) &&
519 filter.matchesWithoutDomain(location, typeMask,
520 thirdParty, sitekey))
521 {
522 if (!collection)
523 return filter;
524
525 collection.push(filter);
526 }
527 }
528 }
529 }
530 } 544 }
531 545
532 return null; 546 return null;
533 } 547 }
534 548
535 /** 549 /**
536 * Checks whether the entries for a particular keyword match a URL 550 * Checks whether the entries for a particular keyword match a URL
537 * @param {string} keyword 551 * @param {string} keyword
538 * @param {string} location 552 * @param {string} location
539 * @param {number} typeMask 553 * @param {number} typeMask
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 890
877 exports.CombinedMatcher = CombinedMatcher; 891 exports.CombinedMatcher = CombinedMatcher;
878 892
879 /** 893 /**
880 * Shared {@link CombinedMatcher} instance that should usually be used. 894 * Shared {@link CombinedMatcher} instance that should usually be used.
881 * @type {CombinedMatcher} 895 * @type {CombinedMatcher}
882 */ 896 */
883 let defaultMatcher = new CombinedMatcher(); 897 let defaultMatcher = new CombinedMatcher();
884 898
885 exports.defaultMatcher = defaultMatcher; 899 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