]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add shallowcopy utility
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 11 Sep 2018 10:01:18 +0000 (11:01 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 11 Sep 2018 10:01:18 +0000 (11:01 +0100)
lualib/lua_util.lua

index 0ce0c18748a7a9e6d61f8992c2163c671edb224f..e0096daa197b469142bfefc62aa51a227bd0dec1 100644 (file)
@@ -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