aboutsummaryrefslogtreecommitdiffstats
path: root/rules
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 /rules
parent9fa0dcd5b10ad58ed55575a5daf4326209a0787a (diff)
downloadrspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.tar.gz
rspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.zip
[Feature] Memoize LPEG grammars
Diffstat (limited to 'rules')
-rw-r--r--rules/global_functions.lua14
1 files changed, 10 insertions, 4 deletions
diff --git a/rules/global_functions.lua b/rules/global_functions.lua
index e3a167a07..3a60e5812 100644
--- a/rules/global_functions.lua
+++ b/rules/global_functions.lua
@@ -178,12 +178,18 @@ function rspamd_redis_make_request(task, redis_params, key, is_write, callback,
return ret,conn,addr
end
+local split_grammar
function rspamd_str_split(s, sep)
local lpeg = require "lpeg"
- sep = lpeg.P(sep)
- local elem = lpeg.C((1 - sep)^0)
- local p = lpeg.Ct(elem * (sep * elem)^0) -- make a table capture
- return lpeg.match(p, s)
+
+ if not split_grammar then
+ sep = lpeg.P(sep)
+ local elem = lpeg.C((1 - sep)^0)
+ local p = lpeg.Ct(elem * (sep * elem)^0)
+ split_grammar = p
+ end
+
+ return lpeg.match(split_grammar, s)
end
-- Metafunctions