lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Alex,

On 8/27/11 4:47 AM, Alexander Gladysh wrote:
Hi, Dimiter,

On Sat, Aug 27, 2011 at 14:24, Dimiter "malkia" Stanev<malkia@gmail.com>  wrote:

...

Can't reproduce your results. I think that mistake in while condition
(while k instead of while k ~= nil) is to blame — your dataset
probably contained a lot of data behind false key.

Aha! That's it! Thanks for spotting it. Knew that there would be some shenanigans - I actually tried for the fist time using repeat / until and it even failed more (by giving even yet more incredible results) - now I understand what was happening...

So  can't think of anything else to optimize it, or make it LJ2 friendly

I try gathering all keys in advance, thinking I'll be isolating pairs()
in one place, then when copying doing

Something like this:

local keys={}
for k,_ in pairs(t) do keys[#keys+1] = k end

-- Then hoping that because pairs() is not called, more can be optimized in the next for loop, but was not able to get it.
for k=1,#keys
    local k = keys[k]
    local v = t[k]
    .... -- do the copying
end

I also started working on non-recursive version, but it became ugly too quickly :)

Cheers