From 1498f2c5cbbc415c898621c233261ff5d41bc15d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 25 Mar 2017 12:27:52 +0000 Subject: [Feature] Memoize LPEG grammars --- src/plugins/lua/phishing.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/plugins/lua/phishing.lua') 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) -- cgit v1.2.3