]> source.dussan.org Git - rspamd.git/commitdiff
Merge branch 'master' into redis-coroutines 2479/head
authorMikhail Galanin <mgalanin@mimecast.com>
Tue, 11 Sep 2018 10:07:58 +0000 (11:07 +0100)
committerMikhail Galanin <mgalanin@mimecast.com>
Tue, 11 Sep 2018 10:07:58 +0000 (11:07 +0100)
1  2 
lualib/lua_redis.lua
lualib/lua_util.lua

Simple merge
index b8e1dbfad58d5b5de6db2049dd32695b1df647cf,e0096daa197b469142bfefc62aa51a227bd0dec1..4b18d854cf7fc2734da97e3a9cf0524fa6a66ea0
@@@ -664,30 -664,25 +664,48 @@@ exports.extract_specific_urls = functio
    return res
  end
  
 +--[[[
 +-- @function lua_util.deepcopy(table)
 +-- params: {
 +- - table
 +-- }
 +-- Performs deep copy of the table. Including metatables
 +--]]
 +local function deepcopy(orig)
 +  local orig_type = type(orig)
 +  local copy
 +  if orig_type == 'table' then
 +    copy = {}
 +    for orig_key, orig_value in next, orig, nil do
 +      copy[deepcopy(orig_key)] = deepcopy(orig_value)
 +    end
 +    setmetatable(copy, deepcopy(getmetatable(orig)))
 +  else -- number, string, boolean, etc
 +    copy = orig
 +  end
 +  return copy
 +end
 +
 +exports.deepcopy = deepcopy
  
+ --[[[
+ -- @function lua_util.shallowcopy(tbl)
+ -- Performs shallow (and fast) copy of a table or another Lua type
+ --]]
+ exports.shallowcopy = function(orig)
+   local orig_type = type(orig)
+   local copy
+   if orig_type == 'table' then
+     copy = {}
+     for orig_key, orig_value in pairs(orig) do
+       copy[orig_key] = orig_value
+     end
+   else
+     copy = orig
+   end
+   return copy
+ end
  -- Debugging support
  local unconditional_debug = false
  local debug_modules = {}