Skip to content

Commit 73516c5

Browse files
committed
encoding/gob: avoid allocating string for map key
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 <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8d966ba commit 73516c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/encoding/gob/decode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,10 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, valu
645645
errorf("invalid type name length %d: exceeds input size", nr)
646646
}
647647
n := int(nr)
648-
name := string(state.b.Bytes()[:n])
648+
name := state.b.Bytes()[:n]
649649
state.b.Drop(n)
650650
// Allocate the destination interface value.
651-
if name == "" {
651+
if len(name) == 0 {
652652
// Copy the nil interface value to the target.
653653
value.Set(reflect.Zero(value.Type()))
654654
return
@@ -658,7 +658,7 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, valu
658658
}
659659
// The concrete type must be registered.
660660
registerLock.RLock()
661-
typ, ok := nameToConcreteType[name]
661+
typ, ok := nameToConcreteType[string(name)]
662662
registerLock.RUnlock()
663663
if !ok {
664664
errorf("name not registered for interface: %q", name)

0 commit comments

Comments
 (0)