Simplify LuaJIT memory grow
This commit is contained in:
parent
65374481ff
commit
7146d83cd4
@ -364,18 +364,14 @@ do
|
|||||||
|
|
||||||
local mem_t = ffi.typeof('struct Memory')
|
local mem_t = ffi.typeof('struct Memory')
|
||||||
|
|
||||||
local function finalizer(mem) ffi.C.free(mem.data) end
|
local function finalizer(memory) ffi.C.free(memory.data) end
|
||||||
|
|
||||||
local function grow_unchecked(memory, old, new)
|
local function grow_unchecked(memory, old, new)
|
||||||
memory.data = ffi.C.realloc(memory.data, new * WASM_PAGE_SIZE)
|
memory.data = ffi.C.realloc(memory.data, new)
|
||||||
memory.min = new
|
|
||||||
|
|
||||||
assert(memory.data ~= nil, 'failed to reallocate')
|
assert(memory.data ~= nil, 'failed to reallocate')
|
||||||
|
|
||||||
local start = memory.data + old * WASM_PAGE_SIZE
|
ffi.fill(memory.data + old, new - old, 0)
|
||||||
local len = (new - old) * WASM_PAGE_SIZE
|
|
||||||
|
|
||||||
ffi.fill(start, len, 0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function memory.new(min, max)
|
function memory.new(min, max)
|
||||||
@ -395,7 +391,8 @@ do
|
|||||||
if new > memory.max then
|
if new > memory.max then
|
||||||
return -1
|
return -1
|
||||||
else
|
else
|
||||||
grow_unchecked(memory, old, new)
|
grow_unchecked(memory, old * WASM_PAGE_SIZE, new * WASM_PAGE_SIZE)
|
||||||
|
memory.min = new
|
||||||
|
|
||||||
return old
|
return old
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user