Index: src/pkg/gob/decode.go |
=================================================================== |
--- a/src/pkg/gob/decode.go |
+++ b/src/pkg/gob/decode.go |
@@ -486,7 +486,7 @@ |
// This state cannot arise for decodeSingle, which is called directly |
// from the user's value, not from the innards of an engine. |
func (dec *Decoder) decodeStruct(engine *decEngine, ut *userTypeInfo, p uintptr, indir int) { |
- p = allocate(ut.base.(*reflect.StructType), p, indir) |
+ p = allocate(ut.base, p, indir) |
state := dec.newDecoderState(&dec.buf) |
state.fieldnum = -1 |
basep := p |
@@ -567,7 +567,7 @@ |
// decodeArray decodes an array and stores it through p, that is, p points to the zeroth element. |
// The length is an unsigned integer preceding the elements. Even though the length is redundant |
// (it's part of the type), it's a useful check and is included in the encoding. |
-func (dec *Decoder) decodeArray(atyp *reflect.ArrayType, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.ErrorString) { |
+func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.ErrorString) { |
if indir > 0 { |
p = allocate(atyp, p, 1) // All but the last level has been allocated by dec.Indirect |
} |
@@ -593,7 +593,7 @@ |
// Maps are encoded as a length followed by key:value pairs. |
// Because the internals of maps are not visible to us, we must |
// use reflection rather than pointer magic. |
-func (dec *Decoder) decodeMap(mtyp *reflect.MapType, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.ErrorString) { |
+func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.ErrorString) { |
if indir > 0 { |
p = allocate(mtyp, p, 1) // All but the last level has been allocated by dec.Indirect |
} |
@@ -643,7 +643,7 @@ |
// decodeSlice decodes a slice and stores the slice header through p. |
// Slices are encoded as an unsigned length followed by the elements. |
-func (dec *Decoder) decodeSlice(atyp *reflect.SliceType, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.ErrorString) { |
+func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.ErrorString) { |
n := int(uintptr(state.decodeUint())) |
if indir > 0 { |
up := unsafe.Pointer(p) |
@@ -685,7 +685,7 @@ |
// decodeInterface decodes an interface value and stores it through p. |
// Interfaces are encoded as the name of a concrete type followed by a value. |
// If the name is empty, the value is nil and no value is sent. |
-func (dec *Decoder) decodeInterface(ityp *reflect.InterfaceType, state *decoderState, p uintptr, indir int) { |
+func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, p uintptr, indir int) { |
// Create an interface reflect.Value. We need one even for the nil case. |
ivalue := reflect.MakeZero(ityp).(*reflect.InterfaceValue) |
// Read the name of the concrete type. |
@@ -823,8 +823,8 @@ |
if op == nil { |
inProgress[rt] = &op |
// Special cases |
- switch t := typ.(type) { |
- case *reflect.ArrayType: |
+ switch t := typ; t.Kind() { |
+ case reflect.Array: |
name = "element of " + name |
elemId := dec.wireType[wireId].ArrayT.Elem |
elemOp, elemIndir := dec.decOpFor(elemId, t.Elem(), name, inProgress) |
@@ -833,7 +833,7 @@ |
state.dec.decodeArray(t, state, uintptr(p), *elemOp, t.Elem().Size(), t.Len(), i.indir, elemIndir, ovfl) |
} |
- case *reflect.MapType: |
+ case reflect.Map: |
name = "element of " + name |
keyId := dec.wireType[wireId].MapT.Key |
elemId := dec.wireType[wireId].MapT.Elem |
@@ -845,7 +845,7 @@ |
state.dec.decodeMap(t, state, uintptr(up), *keyOp, *elemOp, i.indir, keyIndir, elemIndir, ovfl) |
} |
- case *reflect.SliceType: |
+ case reflect.Slice: |
name = "element of " + name |
if t.Elem().Kind() == reflect.Uint8 { |
op = decUint8Array |
@@ -863,7 +863,7 @@ |
state.dec.decodeSlice(t, state, uintptr(p), *elemOp, t.Elem().Size(), i.indir, elemIndir, ovfl) |
} |
- case *reflect.StructType: |
+ case reflect.Struct: |
// Generate a closure that calls out to the engine for the nested type. |
enginePtr, err := dec.getDecEnginePtr(wireId, userType(typ)) |
if err != nil { |
@@ -873,7 +873,7 @@ |
// indirect through enginePtr to delay evaluation for recursive structs. |
dec.decodeStruct(*enginePtr, userType(typ), uintptr(p), i.indir) |
} |
- case *reflect.InterfaceType: |
+ case reflect.Interface: |
op = func(i *decInstr, state *decoderState, p unsafe.Pointer) { |
state.dec.decodeInterface(t, state, uintptr(p), i.indir) |
} |
@@ -956,7 +956,7 @@ |
rt = reflect.PtrTo(rt) |
} else if ut.decIndir > 0 { |
for i := int8(0); i < ut.decIndir; i++ { |
- rt = rt.(*reflect.PtrType).Elem() |
+ rt = rt.Elem() |
} |
} |
var op decOp |
@@ -999,37 +999,37 @@ |
if ut.isGobDecoder { // This test trumps all others. |
return true |
} |
- switch t := ut.base.(type) { |
+ switch t := ut.base; t.Kind() { |
default: |
// chan, etc: cannot handle. |
return false |
- case *reflect.BoolType: |
+ case reflect.Bool: |
return fw == tBool |
- case *reflect.IntType: |
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
return fw == tInt |
- case *reflect.UintType: |
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
return fw == tUint |
- case *reflect.FloatType: |
+ case reflect.Float32, reflect.Float64: |
return fw == tFloat |
- case *reflect.ComplexType: |
+ case reflect.Complex64, reflect.Complex128: |
return fw == tComplex |
- case *reflect.StringType: |
+ case reflect.String: |
return fw == tString |
- case *reflect.InterfaceType: |
+ case reflect.Interface: |
return fw == tInterface |
- case *reflect.ArrayType: |
+ case reflect.Array: |
if !ok || wire.ArrayT == nil { |
return false |
} |
array := wire.ArrayT |
return t.Len() == array.Len && dec.compatibleType(t.Elem(), array.Elem, inProgress) |
- case *reflect.MapType: |
+ case reflect.Map: |
if !ok || wire.MapT == nil { |
return false |
} |
MapType := wire.MapT |
return dec.compatibleType(t.Key(), MapType.Key, inProgress) && dec.compatibleType(t.Elem(), MapType.Elem, inProgress) |
- case *reflect.SliceType: |
+ case reflect.Slice: |
// Is it an array of bytes? |
if t.Elem().Kind() == reflect.Uint8 { |
return fw == tBytes |
@@ -1043,7 +1043,7 @@ |
} |
elem := userType(t.Elem()).base |
return sw != nil && dec.compatibleType(elem, sw.Elem, inProgress) |
- case *reflect.StructType: |
+ case reflect.Struct: |
return true |
} |
return true |
@@ -1093,8 +1093,9 @@ |
// it calls out to compileSingle. |
func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEngine, err os.Error) { |
rt := ut.base |
- srt, ok := rt.(*reflect.StructType) |
- if !ok || ut.isGobDecoder { |
+ srt := rt |
+ if srt.Kind() != reflect.Struct || |
+ ut.isGobDecoder { |
return dec.compileSingle(remoteId, ut) |
} |
var wireStruct *structType |
@@ -1206,7 +1207,7 @@ |
return |
} |
engine := *enginePtr |
- if st, ok := base.(*reflect.StructType); ok && !ut.isGobDecoder { |
+ if st := base; st.Kind() == reflect.Struct && !ut.isGobDecoder { |
if engine.numInstr == 0 && st.NumField() > 0 && len(dec.wireType[wireId].StructT.Field) > 0 { |
name := base.Name() |
errorf("gob: type mismatch: no fields matched compiling decoder for %s", name) |