diff options
author | Rob Pike <r@golang.org> | 2011-03-23 21:49:19 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2011-03-23 21:49:19 -0700 |
commit | d1b75bbc4609087a69bf6bdb908036c58c8947ea (patch) | |
tree | 8681e23ff01fcc7ac04d2d5ca45cd2c3ff60554e | |
parent | 1c05a90ae28df67ae74a2ad49293e11d9222cb1c (diff) | |
download | go-d1b75bbc4609087a69bf6bdb908036c58c8947ea.tar.gz go-d1b75bbc4609087a69bf6bdb908036c58c8947ea.zip |
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
-rw-r--r-- | src/pkg/gob/encoder.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/pkg/gob/encoder.go b/src/pkg/gob/encoder.go index 55481a9885..e52a4de29f 100644 --- a/src/pkg/gob/encoder.go +++ b/src/pkg/gob/encoder.go @@ -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) |