lua-users home
lua-l archive

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


> 1. I didn't want to complain about the speed of the # operator. I
>    think O(log(n)) is just fine to determine the size of a table.
> 
> 2. I'm aware of the fact that t[#t + 1] = v is a common idiom
>    and that the usage of the # operator has a complexity of
>    O(n*log(n)) when used in a loop to fill a table. In many
>    programs that doesn't matter (it's still fast enough and
>    filling a table is O(n*log(n) anyway), so I usually don't
>    care to optimize here.
> 
> 3. Removing the __ipairs metamethod mechanism is not just about
>    the overhead (and speed) of the # operator:
> 
>    a) Beside the repetitive call of luaB_ipairs, it is not
>       possible to return a precalculated value as second item of
>       the iterator triplet that may speed things up.
> 
>    [...]

First, many thanks for the data. We will work over it.

Second, your point 3 is very elucidative, and brings me another
question: you are doing something quite different from the original
ipairs. Is there any special reason why you have to use ipairs for your
iteration? The whole idea of the for loop in Lua is that people can
build their own iterators. Is there a specific reason why yours has to
be packed inside ipairs?

-- Roberto