1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Optimize appending to tables in core.serialize and dump

This commit is contained in:
Lars Mueller 2025-05-02 14:52:43 +02:00 committed by Lars Müller
parent 747857bffa
commit 34e73da424
2 changed files with 16 additions and 4 deletions

View file

@ -122,8 +122,16 @@ function dump(value, indent)
local newline = indent == "" and "" or "\n"
local rope = {}
local function write(str)
table.insert(rope, str)
local write
do
-- Keeping the length of the table as a local variable is *much*
-- faster than invoking the length operator.
-- See https://gitspartv.github.io/LuaJIT-Benchmarks/#test12.
local i = 0
function write(str)
i = i + 1
rope[i] = str
end
end
local n_refs = {}