diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2025-02-17 20:48:29 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2025-02-17 20:49:55 -0800 |
commit | ed48ff4b893d73101c8c4011e73c08bf2630c89d (patch) | |
tree | b82d818cb5119fd46f9f9fd11aa5e8d9b4c0e3dc | |
parent | 3de4819614e1de4e52cb2ed1f15d2f377d48d45c (diff) | |
download | view.love-ed48ff4b893d73101c8c4011e73c08bf2630c89d.tar.gz |
slightly improve deepcopy everywhere
-rw-r--r-- | source_undo.lua | 8 | ||||
-rw-r--r-- | undo.lua | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/source_undo.lua b/source_undo.lua index d91fecd..772e5da 100644 --- a/source_undo.lua +++ b/source_undo.lua @@ -84,12 +84,12 @@ end -- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080 function deepcopy(obj, seen) if type(obj) ~= 'table' then return obj end - if seen and seen[obj] then return seen[obj] end - local s = seen or {} + seen = seen or {} + if seen[obj] then return seen[obj] end local result = setmetatable({}, getmetatable(obj)) - s[obj] = result + seen[obj] = result for k,v in pairs(obj) do - result[deepcopy(k, s)] = deepcopy(v, s) + result[deepcopy(k, seen)] = deepcopy(v, seen) end return result end diff --git a/undo.lua b/undo.lua index 59ca481..8765ffa 100644 --- a/undo.lua +++ b/undo.lua @@ -83,12 +83,12 @@ end -- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080 function deepcopy(obj, seen) if type(obj) ~= 'table' then return obj end - if seen and seen[obj] then return seen[obj] end - local s = seen or {} + seen = seen or {} + if seen[obj] then return seen[obj] end local result = setmetatable({}, getmetatable(obj)) - s[obj] = result + seen[obj] = result for k,v in pairs(obj) do - result[deepcopy(k, s)] = deepcopy(v, s) + result[deepcopy(k, seen)] = deepcopy(v, seen) end return result end |