[5.4] Shrinking of tables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[5.4] Shrinking of tables

Dirk Laurie-2
Is it still the case in Lua 5.4 that the array part of a table is
never shrunk except possibly when you assign a value to a positive
integer index outside it?

Reply | Threaded
Open this post in threaded view
|

Re: [5.4] Shrinking of tables

Roberto Ierusalimschy
> Is it still the case in Lua 5.4 that the array part of a table is
> never shrunk except possibly when you assign a value to a positive
> integer index outside it?

That was not the case in previous versions and it is not the case in 5.4.

  t = {nil, nil, nil, nil}
  -- array part has size 4, hash part has size 0
  t.a = true       -- force a rehash
  -- now, array part has size 0, hash part has size 1

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: [5.4] Shrinking of tables

Dirk Laurie-2
2018-07-06 14:58 GMT+02:00 Roberto Ierusalimschy <[hidden email]>:

>> Is it still the case in Lua 5.4 that the array part of a table is
>> never shrunk except possibly when you assign a value to a positive
>> integer index outside it?
>
> That was not the case in previous versions and it is not the case in 5.4.
>
>   t = {nil, nil, nil, nil}
>   -- array part has size 4, hash part has size 0
>   t.a = true       -- force a rehash
>   -- now, array part has size 0, hash part has size 1

OK, is a rehash still only triggered by an assignment to a new key or
will collectgarbage()
or even something else also do it now?

Reply | Threaded
Open this post in threaded view
|

Re: [5.4] Shrinking of tables

Roberto Ierusalimschy
> OK, is a rehash still only triggered by an assignment to a new key or
> will collectgarbage()
> or even something else also do it now?

Nothing changed here. A rehash is only triggered by an assignment to a
new key, when there is no recognizable free space left in the hash part
to put this new key.

-- Roberto