Fixes that I forgot to add

This commit is contained in:
Robin Wellner 2016-02-23 13:00:41 +01:00
parent 06d5b69b61
commit 63a512707c
2 changed files with 22 additions and 13 deletions

View File

@ -35,6 +35,13 @@ local function Buffer_prereserve(min_size)
end
end
local function Buffer_clear()
buf_size = -1
buf = nil
writable_buf = nil
writable_buf_size = nil
end
local function Buffer_makeBuffer(size)
if writable_buf then
buf = writable_buf
@ -46,10 +53,6 @@ local function Buffer_makeBuffer(size)
Buffer_prereserve(size)
end
local function Buffer_newWriter(size)
Buffer_makeBuffer(size or 0)
end
local function Buffer_newReader(str)
Buffer_makeBuffer(#str)
ffi.copy(buf, str, #str)
@ -90,10 +93,6 @@ local function Buffer_write_data(ct, len, ...)
buf_pos = buf_pos + len
end
local function Buffer_get()
return buf, buf_pos
end
local function Buffer_ensure(numbytes)
if buf_pos + numbytes > buf_size then
error("malformed serialized data")
@ -244,10 +243,10 @@ serialize_value = function(value, seen)
end
local function serialize(value)
Buffer_newWriter()
Buffer_makeBuffer(4096)
local seen = {len = 0}
serialize_value(value, seen)
return Buffer_get()
return buf, buf_pos
end
local function add_to_seen(value, seen)
@ -357,7 +356,15 @@ local function deserialize_Slither(instance, class)
end
return {dumps = function(value)
return ffi.string(serialize(value))
serialize(value)
return ffi.string(buf, buf_size)
end, dumpLoveFile = function(fname, value)
serialize(value)
love.filesystem.write(fname, ffi.string(buf, buf_size))
end, loadLoveFile = function(fname)
local serializedData = love.filesystem.newFileData(fname)
Buffer_newDataReader(serializedData:getPointer(), serializedData:getSize())
return deserialize_value({})
end, loadData = function(data, size)
Buffer_newDataReader(data, size)
return deserialize_value({})
@ -415,4 +422,4 @@ end, unregisterClass = function(name)
classkey_registry[name] = nil
class_deserialize_registry[name] = nil
class_registry[name] = nil
end, reserve_buffer = Buffer_prereserve}
end, reserveBuffer = Buffer_prereserve, clearBuffer = Buffer_clear}

View File

@ -20,7 +20,7 @@ end
if found_bitser_nonreentrant then
sers.bitser_nonreentrant = bitser_nonreentrant.dumps
desers.bitser_nonreentrant = bitser_nonreentrant.loads
bitser_nonreentrant.reserve_buffer(1024 * 1024)
bitser_nonreentrant.reserveBuffer(1024 * 1024)
end
if found_binser then
@ -123,6 +123,7 @@ function love.draw()
end
local outputs = {}
for try = 1, tries do
love.window.setTitle("Running benchmark... [serializing " .. try .. '/' .. tries .. "]")
for sername, serializer in pairs(sers) do
local output
local success, diff = pcall(function()
@ -142,6 +143,7 @@ function love.draw()
end
end
for try = 1, tries do
love.window.setTitle("Running benchmark... [deserializing " .. try .. '/' .. tries .. "]")
for sername, deserializer in pairs(desers) do
local input = outputs[sername]
local success, diff = pcall(function()