Skip to content

Commit

Permalink
use the new type switch multicase to clean up a little.
Browse files Browse the repository at this point in the history
R=rsc
DELTA=28  (7 added, 16 deleted, 5 changed)
OCL=34487
CL=34487
  • Loading branch information
robpike committed Sep 9, 2009
1 parent f4ee9f1 commit f966ba1
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/pkg/gob/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,22 @@ func (enc *Encoder) sendType(origt reflect.Type) {
rt, indir_ := indirect(origt);

// We only send structs - everything else is basic or an error
switch t := rt.(type) {
case *reflect.StructType: // TODO: when compiler handles type lists, can fold these
break; // we handle these
case *reflect.ChanType:
enc.badType(rt);
return;
case *reflect.FuncType:
enc.badType(rt);
return;
case *reflect.MapType:
enc.badType(rt);
return;
case *reflect.InterfaceType:
enc.badType(rt);
switch rt.(type) {
default:
// Basic types do not need to be described.
return;
// Array and slice types are not sent, only their element types.
// If we see one here it's user error.
case *reflect.ArrayType:
case *reflect.StructType:
// Structs do need to be described.
break;
case *reflect.ChanType, *reflect.FuncType, *reflect.MapType, *reflect.InterfaceType:
// Probably a bad field in a struct.
enc.badType(rt);
return;
case *reflect.SliceType:
case *reflect.ArrayType, *reflect.SliceType:
// Array and slice types are not sent, only their element types.
// If we see one here it's user error; probably a bad top-level value.
enc.badType(rt);
return;
default:
return; // basic, not a type to be sent.
}

// Have we already sent this type? This time we ask about the base type.
Expand Down

0 comments on commit f966ba1

Please sign in to comment.