lua-users home
lua-l archive

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


Op Tue, 24 Nov 2020 21:55:11 +0100 schreef Egor Skriptunoff <egor.skriptunoff@gmail.com>:


Perhaps it’s again time to consider adding table.new?

It would be nice to have a function like
table.rebuild( [ t, ] min_array_size, min_hash_size)
which sets size constraints and shrinks the table.

I keep quoting myself. :)
In C++ you can reserve space for n elements in a vector or an unordered map/set.
Once I wrote a patch for 5.3* that added a table.reserve( t, narray, nhash ) function which reserves at least a number of array and hash elements. [1]

The result was that the improvement of the array part was negligible but for the hash part significant.
I couldn't find the benchmark anymore, probably it was removed during a virtual Marie Kondo cleanup.

-- Jasper

* I think it was 5.3.5

[1] http://lua-users.org/lists/lua-l/2018-12/msg00175.html