diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-25 12:27:52 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-25 12:27:52 +0000 |
commit | 1498f2c5cbbc415c898621c233261ff5d41bc15d (patch) | |
tree | 25feb12267af755c27c40c12c2bcea87ad12b55f /src/plugins/lua/phishing.lua | |
parent | 9fa0dcd5b10ad58ed55575a5daf4326209a0787a (diff) | |
download | rspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.tar.gz rspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.zip |
[Feature] Memoize LPEG grammars
Diffstat (limited to 'src/plugins/lua/phishing.lua')
-rw-r--r-- | src/plugins/lua/phishing.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua index 6c42c96f2..d248c7513 100644 --- a/src/plugins/lua/phishing.lua +++ b/src/plugins/lua/phishing.lua @@ -239,12 +239,17 @@ local function phishing_map(mapname, phishmap, id) end end +local lpeg_grammar local function rspamd_str_split_fun(s, sep, func) local lpeg = require "lpeg" - sep = lpeg.P(sep) - local elem = lpeg.C((1 - sep)^0 / func) - local p = lpeg.C(elem * (sep * elem)^0) -- make a table capture - return lpeg.match(p, s) + + if not lpeg_grammar then + sep = lpeg.P(sep) + local elem = lpeg.C((1 - sep)^0 / func) + local p = lpeg.C(elem * (sep * elem)^0) -- make a table capture + lpeg_grammar = p + end + return lpeg.match(lpeg_grammar, s) end local function insert_url_from_string(pool, tbl, str, data) |