From: Vsevolod Stakhov Date: Tue, 11 Sep 2018 10:01:18 +0000 (+0100) Subject: [Minor] Add shallowcopy utility X-Git-Tag: 1.8.0~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0d362c7f25718abd881c90b163945d4b7b80fe1;p=thirdparty%2Frspamd.git [Minor] Add shallowcopy utility --- diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 0ce0c18748..e0096daa19 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -664,6 +664,25 @@ exports.extract_specific_urls = function(params_or_task, lim, need_emails, filte return res end + +--[[[ +-- @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 = {} @@ -697,4 +716,5 @@ exports.debugm = function(mod, ...) end end + return exports