diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-11 11:01:18 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-11 11:01:18 +0100 |
commit | e0d362c7f25718abd881c90b163945d4b7b80fe1 (patch) | |
tree | 230c8afb76e83d289dd92677a8a10348bf6d4807 /lualib/lua_util.lua | |
parent | 86e0d6c14dde85306c7053d2ddac7624c3af21e1 (diff) | |
download | rspamd-e0d362c7f25718abd881c90b163945d4b7b80fe1.tar.gz rspamd-e0d362c7f25718abd881c90b163945d4b7b80fe1.zip |
[Minor] Add shallowcopy utility
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 0ce0c1874..e0096daa1 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 |