libs/core: optimize strip_bytecode() memory usage by avoiding string concatenation
This commit is contained in:
parent
3fac200364
commit
128437f671
1 changed files with 8 additions and 7 deletions
|
@ -554,10 +554,10 @@ function strip_bytecode(code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local strip_function
|
local function strip_function(code)
|
||||||
strip_function = function(code)
|
|
||||||
local count, offset = subint(code, 1, size)
|
local count, offset = subint(code, 1, size)
|
||||||
local stripped, dirty = string.rep("\0", size), offset + count
|
local stripped = { string.rep("\0", size) }
|
||||||
|
local dirty = offset + count
|
||||||
offset = offset + count + int * 2 + 4
|
offset = offset + count + int * 2 + 4
|
||||||
offset = offset + int + subint(code, offset, int) * ins
|
offset = offset + int + subint(code, offset, int) * ins
|
||||||
count, offset = subint(code, offset, int)
|
count, offset = subint(code, offset, int)
|
||||||
|
@ -575,10 +575,11 @@ function strip_bytecode(code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
count, offset = subint(code, offset, int)
|
count, offset = subint(code, offset, int)
|
||||||
stripped = stripped .. code:sub(dirty, offset - 1)
|
stripped[#stripped+1] = code:sub(dirty, offset - 1)
|
||||||
for n = 1, count do
|
for n = 1, count do
|
||||||
local proto, off = strip_function(code:sub(offset, -1))
|
local proto, off = strip_function(code:sub(offset, -1))
|
||||||
stripped, offset = stripped .. proto, offset + off - 1
|
stripped[#stripped+1] = proto
|
||||||
|
offset = offset + off - 1
|
||||||
end
|
end
|
||||||
offset = offset + subint(code, offset, int) * int + int
|
offset = offset + subint(code, offset, int) * int + int
|
||||||
count, offset = subint(code, offset, int)
|
count, offset = subint(code, offset, int)
|
||||||
|
@ -589,8 +590,8 @@ function strip_bytecode(code)
|
||||||
for n = 1, count do
|
for n = 1, count do
|
||||||
offset = offset + subint(code, offset, size) + size
|
offset = offset + subint(code, offset, size) + size
|
||||||
end
|
end
|
||||||
stripped = stripped .. string.rep("\0", int * 3)
|
stripped[#stripped+1] = string.rep("\0", int * 3)
|
||||||
return stripped, offset
|
return table.concat(stripped), offset
|
||||||
end
|
end
|
||||||
|
|
||||||
return code:sub(1,12) .. strip_function(code:sub(13,-1))
|
return code:sub(1,12) .. strip_function(code:sub(13,-1))
|
||||||
|
|
Loading…
Reference in a new issue