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...

   Andrea


On Mon, Nov 23, 2020 at 12:44 PM Egor Skriptunoff <egor.skriptunoff@gmail.com> 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.

Yes.
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