]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix string split memoization
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Mar 2017 09:05:46 +0000 (10:05 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Mar 2017 09:05:46 +0000 (10:05 +0100)
rules/global_functions.lua

index 3a60e58127a6ecda05bee035747f6c4fab096b1a..e3c95c549a1063a098448d1ce28c9874118e92f7 100644 (file)
@@ -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