From 57c94a394c41502446bba5bcf960391ba3d7bc7a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 03:17:01 +0200 Subject: [PATCH 1/2] Infinitely faster filter creation, and safer. --- 4chan_x.user.js | 7 ++++--- script.coffee | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2238bd7e9..44e06430b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -528,15 +528,16 @@ regexps: {}, callbacks: [], init: function() { - var filter, key, m, _i, _len; + var f, filter, key, m, _i, _len; for (key in config.filter) { - if (!(m = conf[key].match(/^(\/.+\/\w{0,})$/gm))) { + if (!(m = conf[key].match(/^\/.+\/\w{0,}$/gm))) { continue; } this.regexps[key] = []; for (_i = 0, _len = m.length; _i < _len; _i++) { filter = m[_i]; - this.regexps[key].push(Function("return " + filter)()); + f = filter.match(/^\/(.+)\/(\w{0,})$/); + this.regexps[key].push(RegExp(f[1], f[2])); } if (this.regexps[key].length) { this.callbacks.push(this[key]); diff --git a/script.coffee b/script.coffee index 6ec3bde6e..7f13f3d2b 100644 --- a/script.coffee +++ b/script.coffee @@ -386,11 +386,12 @@ filter = callbacks: [] init: -> for key of config.filter - unless m = conf[key].match /^(\/.+\/\w{0,})$/gm + unless m = conf[key].match /^\/.+\/\w{0,}$/gm continue @regexps[key] = [] for filter in m - @regexps[key].push Function("return #{filter}")() + f = filter.match /^\/(.+)\/(\w{0,})$/ + @regexps[key].push RegExp f[1], f[2] #only execute what's filterable @callbacks.push @[key] if @regexps[key].length From e64ea74bbec093d589759651b1974c0a277fc738 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 9 Oct 2011 03:25:55 +0200 Subject: [PATCH 2/2] Use * instead of {0,} --- 4chan_x.user.js | 4 ++-- script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 44e06430b..1ec6c3b94 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -530,13 +530,13 @@ init: function() { var f, filter, key, m, _i, _len; for (key in config.filter) { - if (!(m = conf[key].match(/^\/.+\/\w{0,}$/gm))) { + if (!(m = conf[key].match(/^\/.+\/\w*$/gm))) { continue; } this.regexps[key] = []; for (_i = 0, _len = m.length; _i < _len; _i++) { filter = m[_i]; - f = filter.match(/^\/(.+)\/(\w{0,})$/); + f = filter.match(/^\/(.+)\/(\w*)$/); this.regexps[key].push(RegExp(f[1], f[2])); } if (this.regexps[key].length) { diff --git a/script.coffee b/script.coffee index 7f13f3d2b..34b66d199 100644 --- a/script.coffee +++ b/script.coffee @@ -386,11 +386,11 @@ filter = callbacks: [] init: -> for key of config.filter - unless m = conf[key].match /^\/.+\/\w{0,}$/gm + unless m = conf[key].match /^\/.+\/\w*$/gm continue @regexps[key] = [] for filter in m - f = filter.match /^\/(.+)\/(\w{0,})$/ + f = filter.match /^\/(.+)\/(\w*)$/ @regexps[key].push RegExp f[1], f[2] #only execute what's filterable @callbacks.push @[key] if @regexps[key].length