1
0
mirror of https://github.com/golang/go synced 2024-11-19 23:14:47 -07:00

gob: remove another allocation.

The top level bytes.Buffer is always there and can be re-used.
Rpc goes from 83 to 79 mallocs per round trip.

R=rsc
CC=golang-dev
https://golang.org/cl/4271062
This commit is contained in:
Rob Pike 2011-03-23 21:49:19 -07:00
parent 1c05a90ae2
commit d1b75bbc46

View File

@ -21,6 +21,7 @@ type Encoder struct {
countState *encoderState // stage for writing counts
freeList *encoderState // list of free encoderStates; avoids reallocation
buf []byte // for collecting the output.
byteBuf bytes.Buffer // buffer for top-level encoderState
err os.Error
}
@ -219,7 +220,8 @@ func (enc *Encoder) EncodeValue(value reflect.Value) os.Error {
}
enc.err = nil
state := enc.newEncoderState(new(bytes.Buffer))
enc.byteBuf.Reset()
state := enc.newEncoderState(&enc.byteBuf)
enc.sendTypeDescriptor(enc.writer(), state, ut)
enc.sendTypeId(state, ut)