]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: save a call to userType
authorRob Pike <r@golang.org>
Sun, 3 Aug 2014 22:14:59 +0000 (15:14 -0700)
committerRob Pike <r@golang.org>
Sun, 3 Aug 2014 22:14:59 +0000 (15:14 -0700)
Avoid some pressure on the global mutex by lifting the call to userType
out of the closure.
TOTH to Matt Harden.

LGTM=crawshaw, ruiu
R=golang-codereviews, crawshaw, ruiu
CC=golang-codereviews
https://golang.org/cl/117520043

src/pkg/encoding/gob/decode.go

index 76274a0cacd55690b6e2024b4dfdf22f0ca2594b..2367650c8ba6e52c378091db5536baa04830f36c 100644 (file)
@@ -747,13 +747,14 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
 
                case reflect.Struct:
                        // Generate a closure that calls out to the engine for the nested type.
-                       enginePtr, err := dec.getDecEnginePtr(wireId, userType(typ))
+                       ut := userType(typ)
+                       enginePtr, err := dec.getDecEnginePtr(wireId, ut)
                        if err != nil {
                                error_(err)
                        }
                        op = func(i *decInstr, state *decoderState, value reflect.Value) {
                                // indirect through enginePtr to delay evaluation for recursive structs.
-                               dec.decodeStruct(*enginePtr, userType(typ), value)
+                               dec.decodeStruct(*enginePtr, ut, value)
                        }
                case reflect.Interface:
                        op = func(i *decInstr, state *decoderState, value reflect.Value) {