Skip to content

Inconsistent results of tableaux tcopy and shallow_tcopy#3287

Closed
nnposter wants to merge 2 commits intonmap:masterfrom
nnposter:tableaux-pairs
Closed

Inconsistent results of tableaux tcopy and shallow_tcopy#3287
nnposter wants to merge 2 commits intonmap:masterfrom
nnposter:tableaux-pairs

Conversation

@nnposter
Copy link
Copy Markdown

@nnposter nnposter commented Feb 4, 2026

Function tableaux.tcopy produces a full/deep copy of a given table, while tableaux.shallow_tcopy produces a shallow copy.

A user might naturally assume that results from these two functions are identical for flat tables (tables that do not contain nested tables). However, this is not guaranteed. The reason is that the two functions iterate over the table differently: tcopy is using pairs, while shallow_tcopy is using next. When pairs is used, the actual iterations are determined by a __pairs metamethod, not necessarily relying on next.

This PR updates tableaux.tcopy to use next to achieve consistency with shallow_tcopy. It will be merged in after March 1st unless concerns are raised.

@nnposter
Copy link
Copy Markdown
Author

nnposter commented Mar 8, 2026

As a side note, construct

for k, v in next, tbl do
  ...
end

appears to iterate over large tables about 2.5x faster than

local k, v = next(tbl)
while k ~= nil do
  ...
  k, v = next(tbl, k)
end

@nmap-bot nmap-bot closed this in 4418231 Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant