mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Optimize appending to tables in core.serialize
and dump
This commit is contained in:
committed by
Lars Müller
parent
747857bffa
commit
34e73da424
@@ -218,9 +218,13 @@ function core.serialize(value)
|
||||
core.log("deprecated", "Support for dumping functions in `core.serialize` is deprecated.")
|
||||
end
|
||||
local rope = {}
|
||||
-- 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
|
||||
serialize(value, function(text)
|
||||
-- Faster than table.insert(rope, text) on PUC Lua 5.1
|
||||
rope[#rope + 1] = text
|
||||
i = i + 1
|
||||
rope[i] = text
|
||||
end)
|
||||
return table_concat(rope)
|
||||
end
|
||||
|
Reference in New Issue
Block a user