17,105
edits
No edit summary |
(shallowClone: Implement) |
||
Line 293: | Line 293: | ||
local res = {} | local res = {} | ||
for k, v in pairs(obj) do res[p.clone(k)] = p.clone(v) end | for k, v in pairs(obj) do res[p.clone(k)] = p.clone(v) end | ||
return res | |||
end | |||
-- Shallow clone, desirable when operations such as sorting are to be performed | |||
-- on a table where it is not necessary to perform a deep clone of all data within | |||
-- the table's elements | |||
function p.shallowClone(obj) | |||
if type(obj) ~= 'table' then return obj end | |||
local res = {} | |||
for k, v in pairs(obj) do | |||
res[k] = v | |||
end | |||
return res | return res | ||
end | end |