lua-users home
lua-l archive

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


Not related to performance, minor style remarks:

>     for i = 1, q, 1 do
>         k = 3 - k 
>         c = c + 4*k*i
>         j = c
>         local ij = 2*i*(3-k)+1
>         t = t + 4*k
>         while j <= M do
>             S[j] = 0
>             j = j + ij
>             ij = t - ij
>         end
>     end

Third argument to for is optional and equals 1 by default. You can omit
it here.

>     for _, v in next, S do
>         if v > 0 then
>             result[#result + 1] = v
>         end
>     end

It took me a few seconds to understand what this loop does. On the
other hand,

for _, v in pairs(S) do
...
end

is idiomatic and easy to read.
-- 
v <v19930312@gmail.com>