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: Avoid toUpperCase for RegexpFilter Created April 10, 2014, 5:41 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 source = this.domainSource; 322 let source = this.domainSource;
316 if (!(this instanceof RegExpFilter)) { 323 if (!this.domainSourceIsUpperCase) {
Wladimir Palant 2014/04/10 18:43:38 I'd rather not hardcode the RegExpFilter class her
317 // RegExpFilter already have uppercase domains 324 // RegExpFilter already have uppercase domains
318 source = source.toUpperCase(); 325 source = source.toUpperCase();
319 } 326 }
320 let list = source.split(this.domainSeparator); 327 let list = source.split(this.domainSeparator);
321 if (list.length == 1 && list[0][0] != "~") 328 if (list.length == 1 && list[0][0] != "~")
322 { 329 {
323 // Fast track for the common one-domain scenario 330 // Fast track for the common one-domain scenario
324 domains = {__proto__: null, "": false}; 331 domains = {__proto__: null, "": false};
325 if (this.ignoreTrailingDot) 332 if (this.ignoreTrailingDot)
326 list[0] = list[0].replace(/\.+$/, ""); 333 list[0] = list[0].replace(/\.+$/, "");
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 this.regexpSource = regexpSource; 472 this.regexpSource = regexpSource;
466 } 473 }
467 } 474 }
468 exports.RegExpFilter = RegExpFilter; 475 exports.RegExpFilter = RegExpFilter;
469 476
470 RegExpFilter.prototype = 477 RegExpFilter.prototype =
471 { 478 {
472 __proto__: ActiveFilter.prototype, 479 __proto__: ActiveFilter.prototype,
473 480
474 /** 481 /**
482 * @see ActiveFilter.domainSourceIsUpperCase
483 */
484 domainSourceIsUpperCase: true,
485
486 /**
475 * 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 ).
476 * @type Integer 488 * @type Integer
477 */ 489 */
478 length: 1, 490 length: 1,
479 491
480 /** 492 /**
481 * @see ActiveFilter.domainSeparator 493 * @see ActiveFilter.domainSeparator
482 */ 494 */
483 domainSeparator: "|", 495 domainSeparator: "|",
484 496
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 let domains = null; 587 let domains = null;
576 let siteKeys = null; 588 let siteKeys = null;
577 let thirdParty = null; 589 let thirdParty = null;
578 let collapse = null; 590 let collapse = null;
579 let options; 591 let options;
580 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); 592 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null);
581 if (match) 593 if (match)
582 { 594 {
583 options = match[1].toUpperCase().split(","); 595 options = match[1].toUpperCase().split(",");
584 text = match.input.substr(0, match.index); 596 text = match.input.substr(0, match.index);
585 for each (let option in options) 597 for (let option of options)
586 { 598 {
587 let value = null; 599 let value = null;
588 let separatorIndex = option.indexOf("="); 600 let separatorIndex = option.indexOf("=");
589 if (separatorIndex >= 0) 601 if (separatorIndex >= 0)
590 { 602 {
591 value = option.substr(separatorIndex + 1); 603 value = option.substr(separatorIndex + 1);
592 option = option.substr(0, separatorIndex); 604 option = option.substr(0, separatorIndex);
593 } 605 }
594 option = option.replace(/-/, "_"); 606 option = option.replace(/-/, "_");
595 if (option in RegExpFilter.typeMap) 607 if (option in RegExpFilter.typeMap)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 { 810 {
799 if (!selector) 811 if (!selector)
800 { 812 {
801 if (tagName == "*") 813 if (tagName == "*")
802 tagName = ""; 814 tagName = "";
803 815
804 let id = null; 816 let id = null;
805 let additional = ""; 817 let additional = "";
806 if (attrRules) { 818 if (attrRules) {
807 attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g); 819 attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g);
808 for each (let rule in attrRules) { 820 for (let rule of attrRules) {
809 rule = rule.substr(1, rule.length - 2); 821 rule = rule.substr(1, rule.length - 2);
810 let separatorPos = rule.indexOf("="); 822 let separatorPos = rule.indexOf("=");
811 if (separatorPos > 0) { 823 if (separatorPos > 0) {
812 rule = rule.replace(/=/, '="') + '"'; 824 rule = rule.replace(/=/, '="') + '"';
813 additional += "[" + rule + "]"; 825 additional += "[" + rule + "]";
814 } 826 }
815 else { 827 else {
816 if (id) 828 if (id)
817 { 829 {
818 let {Utils} = require("utils"); 830 let {Utils} = require("utils");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 function ElemHideException(text, domains, selector) 882 function ElemHideException(text, domains, selector)
871 { 883 {
872 ElemHideBase.call(this, text, domains, selector); 884 ElemHideBase.call(this, text, domains, selector);
873 } 885 }
874 exports.ElemHideException = ElemHideException; 886 exports.ElemHideException = ElemHideException;
875 887
876 ElemHideException.prototype = 888 ElemHideException.prototype =
877 { 889 {
878 __proto__: ElemHideBase.prototype 890 __proto__: ElemHideBase.prototype
879 }; 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