Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(665)

Unified Diff: src/pkg/gob/type.go

Issue 4301043: update tree for reflect changes (Closed)
Patch Set: diff -r f692a5e90f6f https://go.googlecode.com/hg/ Created 13 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/gob/encoder.go ('k') | src/pkg/http/response_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/gob/type.go
===================================================================
--- a/src/pkg/gob/type.go
+++ b/src/pkg/gob/type.go
@@ -60,8 +60,8 @@
// half speed. If they meet up, there's a cycle.
slowpoke := ut.base // walks half as fast as ut.base
for {
- pt, ok := ut.base.(*reflect.PtrType)
- if !ok {
+ pt := ut.base
+ if pt.Kind() != reflect.Ptr {
break
}
ut.base = pt.Elem()
@@ -70,7 +70,7 @@
return nil, os.ErrorString("can't represent recursive pointer type " + ut.base.String())
}
if ut.indir%2 == 0 {
- slowpoke = slowpoke.(*reflect.PtrType).Elem()
+ slowpoke = slowpoke.Elem()
}
ut.indir++
}
@@ -121,7 +121,7 @@
if implements(rt, check) {
return true, indir
}
- if p, ok := rt.(*reflect.PtrType); ok {
+ if p := rt; p.Kind() == reflect.Ptr {
indir++
if indir > 100 { // insane number of indirections
return false, 0
@@ -132,7 +132,7 @@
break
}
// No luck yet, but if this is a base type (non-pointer), the pointer might satisfy.
- if _, ok := typ.(*reflect.PtrType); !ok {
+ if typ.Kind() != reflect.Ptr {
// Not a pointer, but does the pointer work?
if implements(reflect.PtrTo(typ), check) {
return true, -1
@@ -222,22 +222,43 @@
var (
// Primordial types, needed during initialization.
- tBool = bootstrapType("bool", false, 1)
- tInt = bootstrapType("int", int(0), 2)
- tUint = bootstrapType("uint", uint(0), 3)
- tFloat = bootstrapType("float", float64(0), 4)
- tBytes = bootstrapType("bytes", make([]byte, 0), 5)
- tString = bootstrapType("string", "", 6)
- tComplex = bootstrapType("complex", 0+0i, 7)
- tInterface = bootstrapType("interface", interface{}(nil), 8)
+ tBool = bootstrapType("bool", (*bool)(nil), 1)
+ tInt = bootstrapType("int", (*int)(nil), 2)
+ tUint = bootstrapType("uint", (*uint)(nil), 3)
+ tFloat = bootstrapType("float", (*float64)(nil), 4)
+ tBytes = bootstrapType("bytes", (*[]byte)(nil), 5)
+ tString = bootstrapType("string", (*string)(nil), 6)
+ tComplex = bootstrapType("complex", (*complex128)(nil), 7)
+ tInterface = bootstrapType("interface", (*interface{})(nil), 8)
// Reserve some Ids for compatible expansion
- tReserved7 = bootstrapType("_reserved1", struct{ r7 int }{}, 9)
- tReserved6 = bootstrapType("_reserved1", struct{ r6 int }{}, 10)
- tReserved5 = bootstrapType("_reserved1", struct{ r5 int }{}, 11)
- tReserved4 = bootstrapType("_reserved1", struct{ r4 int }{}, 12)
- tReserved3 = bootstrapType("_reserved1", struct{ r3 int }{}, 13)
- tReserved2 = bootstrapType("_reserved1", struct{ r2 int }{}, 14)
- tReserved1 = bootstrapType("_reserved1", struct{ r1 int }{}, 15)
+ tReserved7 = bootstrapType("_reserved1", (*struct {
+ r7 int
+ })(nil),
+ 9)
+ tReserved6 = bootstrapType("_reserved1", (*struct {
+ r6 int
+ })(nil),
+ 10)
+ tReserved5 = bootstrapType("_reserved1", (*struct {
+ r5 int
+ })(nil),
+ 11)
+ tReserved4 = bootstrapType("_reserved1", (*struct {
+ r4 int
+ })(nil),
+ 12)
+ tReserved3 = bootstrapType("_reserved1", (*struct {
+ r3 int
+ })(nil),
+ 13)
+ tReserved2 = bootstrapType("_reserved1", (*struct {
+ r2 int
+ })(nil),
+ 14)
+ tReserved1 = bootstrapType("_reserved1", (*struct {
+ r1 int
+ })(nil),
+ 15)
)
// Predefined because it's needed by the Decoder
@@ -429,30 +450,30 @@
}()
// Install the top-level type before the subtypes (e.g. struct before
// fields) so recursive types can be constructed safely.
- switch t := rt.(type) {
+ switch t := rt; t.Kind() {
// All basic types are easy: they are predefined.
- case *reflect.BoolType:
+ case reflect.Bool:
return tBool.gobType(), nil
- case *reflect.IntType:
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return tInt.gobType(), nil
- case *reflect.UintType:
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return tUint.gobType(), nil
- case *reflect.FloatType:
+ case reflect.Float32, reflect.Float64:
return tFloat.gobType(), nil
- case *reflect.ComplexType:
+ case reflect.Complex64, reflect.Complex128:
return tComplex.gobType(), nil
- case *reflect.StringType:
+ case reflect.String:
return tString.gobType(), nil
- case *reflect.InterfaceType:
+ case reflect.Interface:
return tInterface.gobType(), nil
- case *reflect.ArrayType:
+ case reflect.Array:
at := newArrayType(name)
types[rt] = at
type0, err = getBaseType("", t.Elem())
@@ -470,7 +491,7 @@
at.init(type0, t.Len())
return at, nil
- case *reflect.MapType:
+ case reflect.Map:
mt := newMapType(name)
types[rt] = mt
type0, err = getBaseType("", t.Key())
@@ -484,7 +505,7 @@
mt.init(type0, type1)
return mt, nil
- case *reflect.SliceType:
+ case reflect.Slice:
// []byte == []uint8 is a special case
if t.Elem().Kind() == reflect.Uint8 {
return tBytes.gobType(), nil
@@ -498,7 +519,7 @@
st.init(type0)
return st, nil
- case *reflect.StructType:
+ case reflect.Struct:
st := newStructType(name)
types[rt] = st
idToType[st.id()] = st
@@ -566,7 +587,7 @@
// used for building the basic types; called only from init()
func bootstrapType(name string, e interface{}, expect typeId) typeId {
- rt := reflect.Typeof(e)
+ rt := reflect.Typeof(e).Elem()
_, present := types[rt]
if present {
panic("bootstrap type already present: " + name + ", " + rt.String())
@@ -655,17 +676,17 @@
}
t := info.id.gobType()
- switch typ := rt.(type) {
- case *reflect.ArrayType:
+ switch typ := rt; typ.Kind() {
+ case reflect.Array:
info.wire = &wireType{ArrayT: t.(*arrayType)}
- case *reflect.MapType:
+ case reflect.Map:
info.wire = &wireType{MapT: t.(*mapType)}
- case *reflect.SliceType:
+ case reflect.Slice:
// []byte == []uint8 is a special case handled separately
if typ.Elem().Kind() != reflect.Uint8 {
info.wire = &wireType{SliceT: t.(*sliceType)}
}
- case *reflect.StructType:
+ case reflect.Struct:
info.wire = &wireType{StructT: t.(*structType)}
}
typeInfoMap[rt] = info
@@ -749,7 +770,7 @@
// Dereference one pointer looking for a named type.
star := ""
if rt.Name() == "" {
- if pt, ok := rt.(*reflect.PtrType); ok {
+ if pt := rt; pt.Kind() == reflect.Ptr {
star = "*"
rt = pt
}
« no previous file with comments | « src/pkg/gob/encoder.go ('k') | src/pkg/http/response_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b