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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 5150730151264256: Issue 354 - Avoid a string copy that is unnecessary most of the time (Closed)
Left Patch Set: Created April 4, 2014, 3:07 p.m.
Right Patch Set: Added domainSourceIsUpperCase Created April 16, 2014, 4:11 p.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 | no next file » | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 domainSeparator: null, 296 domainSeparator: null,
297 297
298 /** 298 /**
299 * Determines whether the trailing dot in domain names isn't important and 299 * Determines whether the trailing dot in domain names isn't important and
300 * should be ignored, must be overridden by subclasses. 300 * should be ignored, must be overridden by subclasses.
301 * @type Boolean 301 * @type Boolean
302 */ 302 */
303 ignoreTrailingDot: true, 303 ignoreTrailingDot: true,
304 304
305 /** 305 /**
306 * Determines whether domainSource is already upper-case,
307 * can be overridden by subclasses.
308 * @type Boolean
309 */
310 domainSourceIsUpperCase: false,
311
312 /**
306 * Map containing domains that this filter should match on/not match on or nul l if the filter should match on all domains 313 * Map containing domains that this filter should match on/not match on or nul l if the filter should match on all domains
307 * @type Object 314 * @type Object
308 */ 315 */
309 get domains() 316 get domains()
310 { 317 {
311 let domains = null; 318 let domains = null;
312 319
313 if (this.domainSource) 320 if (this.domainSource)
314 { 321 {
315 let list = this.domainSource.toUpperCase().split(this.domainSeparator); 322 let source = this.domainSource;
Wladimir Palant 2014/04/08 12:10:05 I see, I didn't realize what this was doing. The
323 if (!this.domainSourceIsUpperCase) {
324 // RegExpFilter already have uppercase domains
325 source = source.toUpperCase();
326 }
327 let list = source.split(this.domainSeparator);
316 if (list.length == 1 && list[0][0] != "~") 328 if (list.length == 1 && list[0][0] != "~")
317 { 329 {
318 // Fast track for the common one-domain scenario 330 // Fast track for the common one-domain scenario
319 domains = {__proto__: null, "": false}; 331 domains = {__proto__: null, "": false};
320 if (this.ignoreTrailingDot) 332 if (this.ignoreTrailingDot)
321 list[0] = list[0].replace(/\.+$/, ""); 333 list[0] = list[0].replace(/\.+$/, "");
322 domains[list[0]] = true; 334 domains[list[0]] = true;
323 } 335 }
324 else 336 else
325 { 337 {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 this.regexpSource = regexpSource; 472 this.regexpSource = regexpSource;
461 } 473 }
462 } 474 }
463 exports.RegExpFilter = RegExpFilter; 475 exports.RegExpFilter = RegExpFilter;
464 476
465 RegExpFilter.prototype = 477 RegExpFilter.prototype =
466 { 478 {
467 __proto__: ActiveFilter.prototype, 479 __proto__: ActiveFilter.prototype,
468 480
469 /** 481 /**
482 * @see ActiveFilter.domainSourceIsUpperCase
483 */
484 domainSourceIsUpperCase: true,
485
486 /**
470 * Number of filters contained, will always be 1 (required to optimize Matcher ). 487 * Number of filters contained, will always be 1 (required to optimize Matcher ).
471 * @type Integer 488 * @type Integer
472 */ 489 */
473 length: 1, 490 length: 1,
474 491
475 /** 492 /**
476 * @see ActiveFilter.domainSeparator 493 * @see ActiveFilter.domainSeparator
477 */ 494 */
478 domainSeparator: "|", 495 domainSeparator: "|",
479 496
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 let domains = null; 587 let domains = null;
571 let siteKeys = null; 588 let siteKeys = null;
572 let thirdParty = null; 589 let thirdParty = null;
573 let collapse = null; 590 let collapse = null;
574 let options; 591 let options;
575 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); 592 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null);
576 if (match) 593 if (match)
577 { 594 {
578 options = match[1].toUpperCase().split(","); 595 options = match[1].toUpperCase().split(",");
579 text = match.input.substr(0, match.index); 596 text = match.input.substr(0, match.index);
580 for each (let option in options) 597 for (let option of options)
581 { 598 {
582 let value = null; 599 let value = null;
583 let separatorIndex = option.indexOf("="); 600 let separatorIndex = option.indexOf("=");
584 if (separatorIndex >= 0) 601 if (separatorIndex >= 0)
585 { 602 {
586 value = option.substr(separatorIndex + 1); 603 value = option.substr(separatorIndex + 1);
587 option = option.substr(0, separatorIndex); 604 option = option.substr(0, separatorIndex);
588 } 605 }
589 option = option.replace(/-/, "_"); 606 option = option.replace(/-/, "_");
590 if (option in RegExpFilter.typeMap) 607 if (option in RegExpFilter.typeMap)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 { 810 {
794 if (!selector) 811 if (!selector)
795 { 812 {
796 if (tagName == "*") 813 if (tagName == "*")
797 tagName = ""; 814 tagName = "";
798 815
799 let id = null; 816 let id = null;
800 let additional = ""; 817 let additional = "";
801 if (attrRules) { 818 if (attrRules) {
802 attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g); 819 attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g);
803 for each (let rule in attrRules) { 820 for (let rule of attrRules) {
804 rule = rule.substr(1, rule.length - 2); 821 rule = rule.substr(1, rule.length - 2);
805 let separatorPos = rule.indexOf("="); 822 let separatorPos = rule.indexOf("=");
806 if (separatorPos > 0) { 823 if (separatorPos > 0) {
807 rule = rule.replace(/=/, '="') + '"'; 824 rule = rule.replace(/=/, '="') + '"';
808 additional += "[" + rule + "]"; 825 additional += "[" + rule + "]";
809 } 826 }
810 else { 827 else {
811 if (id) 828 if (id)
812 { 829 {
813 let {Utils} = require("utils"); 830 let {Utils} = require("utils");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 function ElemHideException(text, domains, selector) 882 function ElemHideException(text, domains, selector)
866 { 883 {
867 ElemHideBase.call(this, text, domains, selector); 884 ElemHideBase.call(this, text, domains, selector);
868 } 885 }
869 exports.ElemHideException = ElemHideException; 886 exports.ElemHideException = ElemHideException;
870 887
871 ElemHideException.prototype = 888 ElemHideException.prototype =
872 { 889 {
873 __proto__: ElemHideBase.prototype 890 __proto__: ElemHideBase.prototype
874 }; 891 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld