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: Created April 4, 2014, 3:07 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 list = this.domainSource.toUpperCase().split(this.domainSeparator);
Wladimir Palant 2014/04/08 12:10:05 I see, I didn't realize what this was doing. The
316 if (list.length == 1 && list[0][0] != "~") 316 if (list.length == 1 && list[0][0] != "~")
317 { 317 {
318 // Fast track for the common one-domain scenario 318 // Fast track for the common one-domain scenario
319 domains = {__proto__: null, "": false}; 319 domains = {__proto__: null, "": false};
320 if (this.ignoreTrailingDot) 320 if (this.ignoreTrailingDot)
321 list[0] = list[0].replace(/\.+$/, ""); 321 list[0] = list[0].replace(/\.+$/, "");
322 domains[list[0]] = true; 322 domains[list[0]] = true;
323 } 323 }
324 else 324 else
325 { 325 {
(...skipping 19 matching lines...) Expand all
345 } 345 }
346 346
347 if (!domains) 347 if (!domains)
348 domains = {__proto__: null}; 348 domains = {__proto__: null};
349 349
350 domains[domain] = include; 350 domains[domain] = include;
351 } 351 }
352 domains[""] = !hasIncludes; 352 domains[""] = !hasIncludes;
353 } 353 }
354 354
355 delete this.domainSource; 355 this.domainSource = null;
356 } 356 }
357 357
358 this.__defineGetter__("domains", function() domains); 358 this.__defineGetter__("domains", function() domains);
359 return this.domains; 359 return this.domains;
360 }, 360 },
361 361
362 /** 362 /**
363 * Checks whether this filter is active on a domain. 363 * Checks whether this filter is active on a domain.
364 */ 364 */
365 isActiveOnDomain: function(/**String*/ docDomain) /**Boolean*/ 365 isActiveOnDomain: function(/**String*/ docDomain) /**Boolean*/
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 /** 738 /**
739 * Base class for element hiding filters 739 * Base class for element hiding filters
740 * @param {String} text see Filter() 740 * @param {String} text see Filter()
741 * @param {String} domains (optional) Host names or domains the filter should be restricted to 741 * @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 742 * @param {String} selector CSS selector for the HTML elements that should be hidden
743 * @constructor 743 * @constructor
744 * @augments ActiveFilter 744 * @augments ActiveFilter
745 */ 745 */
746 function ElemHideBase(text, domains, selector) 746 function ElemHideBase(text, domains, selector)
747 { 747 {
748 ActiveFilter.call(this, text, domains ? domains.toUpperCase() : null); 748 ActiveFilter.call(this, text, domains || null);
749 749
750 if (domains) 750 if (domains)
751 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase(); 751 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, " ").toLowerCase();
752 this.selector = selector; 752 this.selector = selector;
753 } 753 }
754 exports.ElemHideBase = ElemHideBase; 754 exports.ElemHideBase = ElemHideBase;
755 755
756 ElemHideBase.prototype = 756 ElemHideBase.prototype =
757 { 757 {
758 __proto__: ActiveFilter.prototype, 758 __proto__: ActiveFilter.prototype,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 function ElemHideException(text, domains, selector) 865 function ElemHideException(text, domains, selector)
866 { 866 {
867 ElemHideBase.call(this, text, domains, selector); 867 ElemHideBase.call(this, text, domains, selector);
868 } 868 }
869 exports.ElemHideException = ElemHideException; 869 exports.ElemHideException = ElemHideException;
870 870
871 ElemHideException.prototype = 871 ElemHideException.prototype =
872 { 872 {
873 __proto__: ElemHideBase.prototype 873 __proto__: ElemHideBase.prototype
874 }; 874 };
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