mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
Add Lua FlatbufferBuilder Clean() method to enable reuseable builders (#5606)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
8526e12d73
commit
661bedd837
@@ -60,6 +60,23 @@ function m.New(initialSize)
|
||||
return o
|
||||
end
|
||||
|
||||
-- Clears the builder and resets the state. It does not actually clear the backing binary array, it just reuses it as
|
||||
-- needed. This is a performant way to use the builder for multiple constructions without the overhead of multiple
|
||||
-- builder allocations.
|
||||
function mt:Clear()
|
||||
self.finished = false
|
||||
self.nested = false
|
||||
self.minalign = 1
|
||||
self.currentVTable = nil
|
||||
self.objectEnd = nil
|
||||
self.head = #self.bytes -- place the head at the end of the binary array
|
||||
|
||||
-- clear vtables instead of making a new table
|
||||
local vtable = self.vtables
|
||||
local vtableCount = #vtable
|
||||
for i=1,vtableCount do vtable[i] = nil end
|
||||
end
|
||||
|
||||
function mt:Output(full)
|
||||
assert(self.finished, "Builder Not Finished")
|
||||
if full then
|
||||
|
||||
Reference in New Issue
Block a user