|
|
||
|
Alexander Gladysh wrote:
If you can afford to corrupt one of the tables, you can optimize out
second loop (untested code):
function compareTables(t1, t2)
-- all key-value pairs in t1 must be in t2
for k, v in pairs(t1) do
if t2[k] ~= v then return false end
t2[k] = nil
end
return next(t2) == nil -- there must not be other keys in t2
end
Interesting idea. This time I have to do a non-destructive comparison, but it could be useful in other occasions.
(anyway, my question was more out of curiosity than for a real need of to-the-last-ns optimizazion).
Enrico