Dump doesn't need to reuse 'source'
All strings are being reused now, including 'source'.
This commit is contained in:
@@ -487,5 +487,30 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
do -- check reuse of strings in dumps
|
||||
local str = "|" .. string.rep("X", 50) .. "|"
|
||||
local foo = load(string.format([[
|
||||
local str <const> = "%s"
|
||||
return {
|
||||
function () return str end,
|
||||
function () return str end,
|
||||
function () return str end
|
||||
}
|
||||
]], str))
|
||||
-- count occurrences of 'str' inside the dump
|
||||
local dump = string.dump(foo)
|
||||
local _, count = string.gsub(dump, str, {})
|
||||
-- there should be only two occurrences:
|
||||
-- one inside the source, other the string itself.
|
||||
assert(count == 2)
|
||||
|
||||
if T then -- check reuse of strings in undump
|
||||
local funcs = load(dump)()
|
||||
assert(string.format("%p", T.listk(funcs[1])[1]) ==
|
||||
string.format("%p", T.listk(funcs[3])[1]))
|
||||
end
|
||||
end
|
||||
|
||||
print('OK')
|
||||
return deep
|
||||
|
||||
Reference in New Issue
Block a user