aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/dkim_signing.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/dkim_signing.lua
parent9fa0dcd5b10ad58ed55575a5daf4326209a0787a (diff)
downloadrspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.tar.gz
rspamd-1498f2c5cbbc415c898621c233261ff5d41bc15d.zip
[Feature] Memoize LPEG grammars
Diffstat (limited to 'src/plugins/lua/dkim_signing.lua')
-rw-r--r--src/plugins/lua/dkim_signing.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua
index 8777afe93..c224c241a 100644
--- a/src/plugins/lua/dkim_signing.lua
+++ b/src/plugins/lua/dkim_signing.lua
@@ -40,16 +40,19 @@ local E = {}
local N = 'dkim_signing'
local redis_params
+local template_grammar
local function simple_template(tmpl, keys)
local lpeg = require "lpeg"
- local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" }
- local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) }
- local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") }
+ if not template_grammar then
+ local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" }
+ local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) }
+ local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") }
- local rep = lpeg.Cs((var + var_braced + 1)^0)
+ template_grammar = lpeg.Cs((var + var_braced + 1)^0)
+ end
- return lpeg.match(rep, tmpl)
+ return lpeg.match(template_grammar, tmpl)
end
local function dkim_signing_cb(task)