]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: avoid allocating string for map key
authorDavid Crawshaw <crawshaw@golang.org>
Mon, 27 Jun 2016 15:07:08 +0000 (11:07 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Tue, 28 Jun 2016 01:50:48 +0000 (01:50 +0000)
On linux/386 compared to tip:

name                     old time/op  new time/op  delta
DecodeInterfaceSlice-40  1.23ms ± 1%  1.17ms ± 1%  -4.93%  (p=0.000 n=9+10)

Recovers about half the performance regression from Go 1.6 on 386.

For #16117.

Change-Id: Ie8676d92a4da3e27ff21b91a98b3e13d16730ba1
Reviewed-on: https://go-review.googlesource.com/24468
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/encoding/gob/decode.go

index 3b2249f6168e5887fdffeb3a6b89760fd85dcdd8..9645dc5790644792f77af597670789a3f0e1acb8 100644 (file)
@@ -645,10 +645,10 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, valu
                errorf("invalid type name length %d: exceeds input size", nr)
        }
        n := int(nr)
-       name := string(state.b.Bytes()[:n])
+       name := state.b.Bytes()[:n]
        state.b.Drop(n)
        // Allocate the destination interface value.
-       if name == "" {
+       if len(name) == 0 {
                // Copy the nil interface value to the target.
                value.Set(reflect.Zero(value.Type()))
                return
@@ -658,7 +658,7 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, valu
        }
        // The concrete type must be registered.
        registerLock.RLock()
-       typ, ok := nameToConcreteType[name]
+       typ, ok := nameToConcreteType[string(name)]
        registerLock.RUnlock()
        if !ok {
                errorf("name not registered for interface: %q", name)