lua-users home
lua-l archive

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

Question: why a re-hash is wrong when assigning a nil? 

We do want the table to shrink when it becomes less populated.

If you dis-allow this, then tables would only grow...


On Mon, Nov 23, 2020 at 12:44 PM Egor Skriptunoff <> wrote:
On Mon, Nov 23, 2020 at 11:26 PM Luiz Henrique de Figueiredo wrote:
It seems to me that the issue, if any, is creating new entries in a
table, not assigning nils.

When nil is assigned to a non-existing key, a table rehash may be triggered as if a new element was inserted.
This behaviour is obviously wrong.
Table rehashing is a very expensive operation, so it's worth adding a check on nil here.

Correct behaviour:
Nothing should be done if nil is assigned to a non-existing key.


Andrea Vitali