lua-users home
lua-l archive

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

On Mon, Nov 23, 2020 at 11:12 AM Roberto Ierusalimschy <> wrote:
>    for j = base_index + game_size, base_index + 2*game_size - 1 do
>       game_field[j] = nil
>    end

Anyone that spends time initializing an array with nil's is not
really concerned with performance. If you remove that pointless
loop from the program, the difference disapears.

(This issue is really a simple variation of what was discussed in this
list a short time ago.)

Yet someone might need to initialize an array with a large batch of unknown values (read from an input file, for example), quite a few of which might be nil, but you can't know which ones in advance without wasting cycles on checking if it's nil right before assigning (and why would you because initializing a new index with nil appears to be a no-op, so there doesn't appear to be a reason to check for nil). As such, initializing with nil is a legitimate use case and shouldn't be subject to potentially a 3,000x slowdown penalty.