Reduce allocations when reusing a Builder.

Add the function `Reset` to the Builder, which facilitates reuse of the
underlying byte slice.
This commit is contained in:
rw
2015-04-02 19:33:00 -07:00
parent ace7fa8094
commit d756efbf76
3 changed files with 29 additions and 8 deletions

View File

@@ -1254,9 +1254,11 @@ func BenchmarkBuildGold(b *testing.B) {
reuse_fred := []byte("Fred")
b.SetBytes(bytes_length)
bldr := flatbuffers.NewBuilder(512)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
bldr := flatbuffers.NewBuilder(0)
bldr.Reset()
str := bldr.CreateByteString(reuse_str)
test1 := bldr.CreateByteString(reuse_test1)
test2 := bldr.CreateByteString(reuse_test2)