diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-27 10:05:46 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-27 10:05:46 +0100 |
commit | ec3558f1d0a8b70f71477edb6cd7cf39884e2d1b (patch) | |
tree | 5dac133ce4cdd765fa8ac4bc1af5b4fc1147597e /rules | |
parent | 7522631b4a5d98a7a38429716f0e56286c7d3c2c (diff) | |
download | rspamd-ec3558f1d0a8b70f71477edb6cd7cf39884e2d1b.tar.gz rspamd-ec3558f1d0a8b70f71477edb6cd7cf39884e2d1b.zip |
[Fix] Fix string split memoization
Diffstat (limited to 'rules')
-rw-r--r-- | rules/global_functions.lua | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rules/global_functions.lua b/rules/global_functions.lua index 3a60e5812..e3c95c549 100644 --- a/rules/global_functions.lua +++ b/rules/global_functions.lua @@ -178,18 +178,20 @@ function rspamd_redis_make_request(task, redis_params, key, is_write, callback, return ret,conn,addr end -local split_grammar +local split_grammar = {} function rspamd_str_split(s, sep) local lpeg = require "lpeg" - - 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 + local gr = split_grammar[sep] + + if not gr then + local _sep = lpeg.P(sep) + local elem = lpeg.C((1 - _sep)^0) + local p = lpeg.Ct(elem * (_sep * elem)^0) + gr = p + split_grammar[sep] = gr end - return lpeg.match(split_grammar, s) + return gr:match(s) end -- Metafunctions |