Provide possibility to reuse Builder and Reader
mzaks opened this issue · comments
Maxim Zaks commented
As discussed in #25
Joakim Hassila commented
I think this is one of the biggest wins for repeated building&reading - e.g. the builder has a bunch of properties that are objects and needs to be set up / allocated regardless of whether cache is in use - e.g.
public var cache : [ObjectIdentifier : Offset] = [:]
public var inProgress : Set<ObjectIdentifier> = []
public var deferedBindings : [(object:Any, cursor:Int)] = []
Would be nice to add something like
public static func fromReader(r : FlatBufferReader) -> FooBarContainer {
let reader = r
let objectOffset = reader.rootObjectOffset
return create(reader, objectOffset : objectOffset)!
}
and
public func toByteArray (b :FlatBufferBuilder) -> [UInt8] {
let builder = b
let offset = addToByteArray(builder)
performLateBindings(builder)
return try! builder.finish(offset, fileIdentifier: nil)
}
and corresponding reader&builder 'reset' methods.
Joakim Hassila commented
A lazy instance would probably want to keep its reader-per-instance though (can't think of something decent there right now otherwise).
Joakim Hassila commented
Addressed second half in #40 - I think we can close this one after that one is integrated.