diff options
author | portix <none@none> | 2013-03-09 15:27:00 +0100 |
---|---|---|
committer | portix <none@none> | 2013-03-09 15:27:00 +0100 |
commit | 6fad72d9f2d692d741b7e1863381674ba9df0ae5 (patch) | |
tree | 34c01f863ec25005da899c51fdf6f28e4fe3593a /scripts | |
parent | ebe7965f34fd82b5bdf7b3d1c1faf497420402f9 (diff) | |
download | dwb-6fad72d9f2d692d741b7e1863381674ba9df0ae5.zip |
Compile escape regexes only once in Glob constructor
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/dwb.js | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js index 34bb7998..8d58b838 100644 --- a/scripts/lib/dwb.js +++ b/scripts/lib/dwb.js @@ -31,17 +31,21 @@ Object.defineProperties(this, { "Glob" : { - value : function(p) { - var cnstr = function (m, f, s) { - return s == "?" ? (f ? "\?" : ".") : (f ? "\*" : ".*"); + value : (function() { + var esc = new RegExp("[-\/\\^$+.()|[\]{}]", "g"); + var matcher = new RegExp("(\\\\)?([*?])", "g"); + return function(p) { + var cnstr = function (m, f, s) { + return f ? m : s == "?" ? "." : ".*"; + }; + var regex = new RegExp("^" + p.replace(esc, '\\$&').replace(matcher, cnstr) + "$"); + return Object.create(Object.prototype, { + match : { value : function(string) { return regex.test(string); } }, + toString : { value : function() { return p; } } + }); + }; - var regex = new RegExp("^" + p.replace(/[-\/\\^$+.()|[\]{}]/g, '\\$&'). - replace(/(\\)?([*?])/g, cnstr) + "$"); - return Object.create(Object.prototype, { - match : { value : function(string) { return regex.test(string); } }, - toString : { value : function() { return pattern; } } - }); - } + })() }, "provide" : { @@ -103,7 +107,8 @@ var id = 0; var timeStamp = new Date().getTime(); return function() { - return checksum(timeStamp + (++id) + path, ChecksumType.sha1); + id++; + return checksum(timeStamp + (id) + path, ChecksumType.sha1); }; })(); var id = "_" + generateId(); |