lua-users home
lua-l archive

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


Hi, Dimiter!

On Sat, Aug 27, 2011 at 21:44, Dimiter "malkia" Stanev <malkia@gmail.com> wrote:
> On 8/27/11 4:47 AM, Alexander Gladysh wrote:
>> 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

No, as I understand it, whole function must be pairs-free for this to
work. Maybe I'm wrong, that's a wild guess. (You may try to move the
loop to a separate function to try this hypothesis.)

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

Thank you for your efforts, but I think that we'we hit the limit here
(unless that suggestion with moving pairs-free loop to a separate
function would work). Short of making pairs() a fast C function (or
however it is called in LJ2), we're out of options here.

Alexander.