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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -307,17 +307,22 @@ ActiveFilter.prototype =
* @type Object
*/
get domains()
{
let domains = null;
if (this.domainSource)
{
- let list = this.domainSource.split(this.domainSeparator);
+ let source = this.domainSource;
+ if (!(this instanceof RegExpFilter)) {
Wladimir Palant 2014/04/10 18:43:38 I'd rather not hardcode the RegExpFilter class her
+ // RegExpFilter already have uppercase domains
+ source = source.toUpperCase();
+ }
+ let list = source.split(this.domainSeparator);
if (list.length == 1 && list[0][0] != "~")
{
// Fast track for the common one-domain scenario
domains = {__proto__: null, "": false};
if (this.ignoreTrailingDot)
list[0] = list[0].replace(/\.+$/, "");
domains[list[0]] = true;
}
@@ -347,17 +352,17 @@ ActiveFilter.prototype =
if (!domains)
domains = {__proto__: null};
domains[domain] = include;
}
domains[""] = !hasIncludes;
}
- delete this.domainSource;
+ this.domainSource = null;
}
this.__defineGetter__("domains", function() domains);
return this.domains;
},
/**
* Checks whether this filter is active on a domain.
@@ -740,17 +745,17 @@ WhitelistFilter.prototype =
* @param {String} text see Filter()
* @param {String} domains (optional) Host names or domains the filter should be restricted to
* @param {String} selector CSS selector for the HTML elements that should be hidden
* @constructor
* @augments ActiveFilter
*/
function ElemHideBase(text, domains, selector)
{
- ActiveFilter.call(this, text, domains ? domains.toUpperCase() : null);
+ ActiveFilter.call(this, text, domains || null);
if (domains)
this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, "").toLowerCase();
this.selector = selector;
}
exports.ElemHideBase = ElemHideBase;
ElemHideBase.prototype =
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld