reflect: add Type.Bits method, add tags to prohibit conversions

gob: substitute slice for map

R=r
CC=golang-dev
https://golang.org/cl/1699045
This commit is contained in:
Russ Cox 2010-06-21 13:19:29 -07:00
parent 2fc0b4f01b
commit fc090a3a54
9 changed files with 112 additions and 144 deletions

View file

@ -601,7 +601,7 @@ func encodeMap(b *bytes.Buffer, rt reflect.Type, p uintptr, keyOp, elemOp encOp,
return state.err
}
var encOpMap = map[reflect.Kind]encOp{
var encOpMap = []encOp{
reflect.Bool: encBool,
reflect.Int: encInt,
reflect.Int8: encInt8,
@ -624,8 +624,12 @@ var encOpMap = map[reflect.Kind]encOp{
// the indirection count to reach it.
func encOpFor(rt reflect.Type) (encOp, int, os.Error) {
typ, indir := indirect(rt)
op, ok := encOpMap[typ.Kind()]
if !ok {
var op encOp
k := typ.Kind()
if int(k) < len(encOpMap) {
op = encOpMap[k]
}
if op == nil {
// Special cases
switch t := typ.(type) {
case *reflect.SliceType: