mzaks / FlatBuffersSwift

This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set initial capacity for vectors

hassila opened this issue · comments

The following small change to codegen removed 1M allocations and improved decoding with ~20%:

        let offset_list : Offset? = reader.getOffset(objectOffset, propertyIndex: 0)
        let length_list = reader.getVectorLength(offset_list)
        if(length_list > 0){
            var index = 0
--->            _result.list.reserveCapacity(length_list)
            while index < length_list {
                _result.list.append(FooBar.create(reader, objectOffset: reader.getVectorOffsetElement(offset_list!, index: index)))
                index += 1
            }
        }