Merge pull request #319 from MayhemYDG/filter

Infinitely faster filter creation, and safer.
This commit is contained in:
James Campos 2011-10-08 18:26:52 -07:00
commit 656d004f64
2 changed files with 7 additions and 5 deletions

View File

@ -528,15 +528,16 @@
regexps: {}, regexps: {},
callbacks: [], callbacks: [],
init: function() { init: function() {
var filter, key, m, _i, _len; var f, filter, key, m, _i, _len;
for (key in config.filter) { for (key in config.filter) {
if (!(m = conf[key].match(/^(\/.+\/\w{0,})$/gm))) { if (!(m = conf[key].match(/^\/.+\/\w*$/gm))) {
continue; continue;
} }
this.regexps[key] = []; this.regexps[key] = [];
for (_i = 0, _len = m.length; _i < _len; _i++) { for (_i = 0, _len = m.length; _i < _len; _i++) {
filter = m[_i]; filter = m[_i];
this.regexps[key].push(Function("return " + filter)()); f = filter.match(/^\/(.+)\/(\w*)$/);
this.regexps[key].push(RegExp(f[1], f[2]));
} }
if (this.regexps[key].length) { if (this.regexps[key].length) {
this.callbacks.push(this[key]); this.callbacks.push(this[key]);

View File

@ -386,11 +386,12 @@ filter =
callbacks: [] callbacks: []
init: -> init: ->
for key of config.filter for key of config.filter
unless m = conf[key].match /^(\/.+\/\w{0,})$/gm unless m = conf[key].match /^\/.+\/\w*$/gm
continue continue
@regexps[key] = [] @regexps[key] = []
for filter in m for filter in m
@regexps[key].push Function("return #{filter}")() f = filter.match /^\/(.+)\/(\w*)$/
@regexps[key].push RegExp f[1], f[2]
#only execute what's filterable #only execute what's filterable
@callbacks.push @[key] if @regexps[key].length @callbacks.push @[key] if @regexps[key].length