perf: split caching in state, cache and module

This commit is contained in:
Folke Lemaitre 2022-11-22 21:12:33 +01:00
parent a543134b8c
commit 54d5ff18f5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
8 changed files with 455 additions and 395 deletions

View file

@ -185,4 +185,37 @@ function M.error(msg)
})
end
function M._dump(value, result)
local t = type(value)
if t == "number" or t == "boolean" then
table.insert(result, tostring(value))
elseif t == "string" then
table.insert(result, ("%q"):format(value))
elseif t == "table" then
table.insert(result, "{")
local i = 1
---@diagnostic disable-next-line: no-unknown
for k, v in pairs(value) do
if k == i then
elseif type(k) == "string" then
table.insert(result, ("[%q]="):format(k))
else
table.insert(result, k .. "=")
end
M._dump(v, result)
table.insert(result, ",")
i = i + 1
end
table.insert(result, "}")
else
error("Unsupported type " .. t)
end
end
function M.dump(value)
local result = {}
M._dump(value, result)
return table.concat(result, "")
end
return M