encoding/gob: save a call to userType

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
This commit is contained in:
Rob Pike 2014-08-03 15:14:59 -07:00
parent aa69a3c386
commit fdaeec580f
1 changed files with 3 additions and 2 deletions

View 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) {