From: Mikhail Galanin Date: Tue, 11 Sep 2018 10:07:58 +0000 (+0100) Subject: Merge branch 'master' into redis-coroutines X-Git-Tag: 1.8.0~143^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=09551bcf6ad0033e5e56e53b9d2e7b05d4d91996;p=rspamd.git Merge branch 'master' into redis-coroutines --- 09551bcf6ad0033e5e56e53b9d2e7b05d4d91996 diff --cc lualib/lua_util.lua index b8e1dbfad,e0096daa1..4b18d854c --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@@ -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 = {}