aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/phishing.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-25 12:27:52 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-25 12:27:52 +0000
commit1498f2c5cbbc415c898621c233261ff5d41bc15d (patch)
tree25feb12267af755c27c40c12c2bcea87ad12b55f /src/plugins/lua/phishing.lua
parent9fa0dcd5b10ad58ed55575a5daf4326209a0787a (diff)
downloadrspamd-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.lua13
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)