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

Side by Side Diff: lib/filterClasses.js

Issue 5150730151264256: Issue 354 - Avoid a string copy that is unnecessary most of the time (Closed)
Patch Set: Avoid toUpperCase for RegexpFilter Created April 10, 2014, 5:41 p.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 <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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 /** 305 /**
306 * Map containing domains that this filter should match on/not match on or nul l if the filter should match on all domains 306 * 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 307 * @type Object
308 */ 308 */
309 get domains() 309 get domains()
310 { 310 {
311 let domains = null; 311 let domains = null;
312 312
313 if (this.domainSource) 313 if (this.domainSource)
314 { 314 {
315 let list = this.domainSource.split(this.domainSeparator); 315 let source = this.domainSource;
316 if (!(this instanceof RegExpFilter)) {
Wladimir Palant 2014/04/10 18:43:38 I'd rather not hardcode the RegExpFilter class her
317 // RegExpFilter already have uppercase domains
318 source = source.toUpperCase();
319 }
320 let list = source.split(this.domainSeparator);
316 if (list.length == 1 && list[0][0] != "~") 321 if (list.length == 1 && list[0][0] != "~")
317 { 322 {
318 // Fast track for the common one-domain scenario 323 // Fast track for the common one-domain scenario
319 domains = {__proto__: null, "": false}; 324 domains = {__proto__: null, "": false};
320 if (this.ignoreTrailingDot) 325 if (this.ignoreTrailingDot)
321 list[0] = list[0].replace(/\.+$/, ""); 326 list[0] = list[0].replace(/\.+$/, "");
322 domains[list[0]] = true; 327 domains[list[0]] = true;
323 } 328 }
324 else 329 else
325 { 330 {
(...skipping 19 matching lines...) Expand all
345 } 350 }
346 351
347 if (!domains) 352 if (!domains)
348 domains = {__proto__: null}; 353 domains = {__proto__: null};
349 354
350 domains[domain] = include; 355 domains[domain] = include;
351 } 356 }
352 domains[""] = !hasIncludes; 357 domains[""] = !hasIncludes;
353 } 358 }
354 359
355 delete this.domainSource; 360 this.domainSource = null;
356 } 361 }
357 362
358 this.__defineGetter__("domains", function() domains); 363 this.__defineGetter__("domains", function() domains);
359 return this.domains; 364 return this.domains;
360 }, 365 },
361 366
362 /** 367 /**
363 * Checks whether this filter is active on a domain. 368 * Checks whether this filter is active on a domain.
364 */ 369 */
365 isActiveOnDomain: function(/**String*/ docDomain) /**Boolean*/ 370 isActiveOnDomain: function(/**String*/ docDomain) /**Boolean*/
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 /** 743 /**
739 * Base class for element hiding filters 744 * Base class for element hiding filters
740 * @param {String} text see Filter() 745 * @param {String} text see Filter()
741 * @param {String} domains (optional) Host names or domains the filter should be restricted to 746 * @param {String} domains (optional) Host names or domains the filter should be restricted to
742 * @param {String} selector CSS selector for the HTML elements that should be hidden 747 * @param {String} selector CSS selector for the HTML elements that should be hidden
743 * @constructor 748 * @constructor
744 * @augments ActiveFilter 749 * @augments ActiveFilter
745 */ 750 */
746 function ElemHideBase(text, domains, selector) 751 function ElemHideBase(text, domains, selector)
747 { 752 {
748 ActiveFilter.call(this, text, domains ? domains.toUpperCase() : null); 753 ActiveFilter.call(this, text, domains || null);
749 754
750 if (domains) 755 if (domains)
751 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase(); 756 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase();
752 this.selector = selector; 757 this.selector = selector;
753 } 758 }
754 exports.ElemHideBase = ElemHideBase; 759 exports.ElemHideBase = ElemHideBase;
755 760
756 ElemHideBase.prototype = 761 ElemHideBase.prototype =
757 { 762 {
758 __proto__: ActiveFilter.prototype, 763 __proto__: ActiveFilter.prototype,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 function ElemHideException(text, domains, selector) 870 function ElemHideException(text, domains, selector)
866 { 871 {
867 ElemHideBase.call(this, text, domains, selector); 872 ElemHideBase.call(this, text, domains, selector);
868 } 873 }
869 exports.ElemHideException = ElemHideException; 874 exports.ElemHideException = ElemHideException;
870 875
871 ElemHideException.prototype = 876 ElemHideException.prototype =
872 { 877 {
873 __proto__: ElemHideBase.prototype 878 __proto__: ElemHideBase.prototype
874 }; 879 };
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