From 3e9dbe143d3338f5f13a5e421ea593adff482da0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Jan 2024 15:16:26 -0300 Subject: New function 'table.create' Creates a table preallocating memory. (It just exports to Lua the API function 'lua_createtable'.) --- testes/sort.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'testes') diff --git a/testes/sort.lua b/testes/sort.lua index 40bb2d8a..45014652 100644 --- a/testes/sort.lua +++ b/testes/sort.lua @@ -3,6 +3,27 @@ print "testing (parts of) table library" +do print "testing 'table.create'" + collectgarbage() + local m = collectgarbage("count") * 1024 + local t = table.create(10000) + local memdiff = collectgarbage("count") * 1024 - m + assert(memdiff > 10000 * 4) + for i = 1, 20 do + assert(#t == i - 1) + t[i] = 0 + end + assert(not T or T.querytab(t) == 10000) + t = nil + collectgarbage() + m = collectgarbage("count") * 1024 + t = table.create(0, 1024) + memdiff = collectgarbage("count") * 1024 - m + assert(memdiff > 1024 * 12) + assert(not T or select(2, T.querytab(t)) == 1024) +end + + print "testing unpack" local unpack = table.unpack -- cgit v1.2.3-55-g6feb