Commit e5c21ec6 authored by rw's avatar rw

invoke many fewer growth events

parent e11da87a
...@@ -34,11 +34,8 @@ func NewBuilder(initialSize int) *Builder { ...@@ -34,11 +34,8 @@ func NewBuilder(initialSize int) *Builder {
// Reset truncates the underlying Builder buffer, facilitating alloc-free // Reset truncates the underlying Builder buffer, facilitating alloc-free
// reuse of a Builder. // reuse of a Builder.
func (b *Builder) Reset() { func (b *Builder) Reset() {
b.head = UOffsetT(0)
b.minalign = 1
if b.Bytes != nil { if b.Bytes != nil {
b.Bytes = b.Bytes[:0] b.Bytes = b.Bytes[:cap(b.Bytes)]
} }
if b.vtables != nil { if b.vtables != nil {
...@@ -48,6 +45,9 @@ func (b *Builder) Reset() { ...@@ -48,6 +45,9 @@ func (b *Builder) Reset() {
if b.vtable != nil { if b.vtable != nil {
b.vtable = b.vtable[:0] b.vtable = b.vtable[:0]
} }
b.head = UOffsetT(len(b.Bytes))
b.minalign = 1
} }
// StartObject initializes bookkeeping for writing a new object. // StartObject initializes bookkeeping for writing a new object.
...@@ -196,9 +196,6 @@ func (b *Builder) growByteBuffer() { ...@@ -196,9 +196,6 @@ func (b *Builder) growByteBuffer() {
middle := newLen / 2 middle := newLen / 2
copy(b.Bytes[middle:], b.Bytes[:middle]) 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. // Head gives the start of useful data in the underlying byte buffer.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment