From ec3558f1d0a8b70f71477edb6cd7cf39884e2d1b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 27 Mar 2017 10:05:46 +0100 Subject: [Fix] Fix string split memoization --- rules/global_functions.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'rules') 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 -- cgit v1.2.3