From e5c21ec66685df0b3e113a9e708a2d4458e9d859 Mon Sep 17 00:00:00 2001 From: rw Date: Sat, 9 May 2015 16:32:26 -0700 Subject: [PATCH] invoke many fewer growth events --- go/builder.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/go/builder.go b/go/builder.go index 0484af7b6..81905f1a4 100644 --- a/go/builder.go +++ b/go/builder.go @@ -34,11 +34,8 @@ func NewBuilder(initialSize int) *Builder { // Reset truncates the underlying Builder buffer, facilitating alloc-free // reuse of a Builder. func (b *Builder) Reset() { - b.head = UOffsetT(0) - b.minalign = 1 - if b.Bytes != nil { - b.Bytes = b.Bytes[:0] + b.Bytes = b.Bytes[:cap(b.Bytes)] } if b.vtables != nil { @@ -48,6 +45,9 @@ func (b *Builder) Reset() { if b.vtable != nil { b.vtable = b.vtable[:0] } + + b.head = UOffsetT(len(b.Bytes)) + b.minalign = 1 } // StartObject initializes bookkeeping for writing a new object. @@ -196,9 +196,6 @@ func (b *Builder) growByteBuffer() { middle := newLen / 2 copy(b.Bytes[middle:], b.Bytes[:middle]) - for i := 0; i < middle; i++ { - b.Bytes[i] = 0 - } } // Head gives the start of useful data in the underlying byte buffer.