Commit 3a52cf56 authored by Rob Pike's avatar Rob Pike

gob: delete some unused bits from the GobEncoder/GobDecoder code.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4631076
parent c2e0d604
...@@ -741,7 +741,7 @@ func (dec *Decoder) ignoreInterface(state *decoderState) { ...@@ -741,7 +741,7 @@ func (dec *Decoder) ignoreInterface(state *decoderState) {
// decodeGobDecoder decodes something implementing the GobDecoder interface. // decodeGobDecoder decodes something implementing the GobDecoder interface.
// The data is encoded as a byte slice. // The data is encoded as a byte slice.
func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value, index int) { func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value) {
// Read the bytes for the value. // Read the bytes for the value.
b := make([]byte, state.decodeUint()) b := make([]byte, state.decodeUint())
_, err := state.b.Read(b) _, err := state.b.Read(b)
...@@ -969,7 +969,7 @@ func (dec *Decoder) gobDecodeOpFor(ut *userTypeInfo) (*decOp, int) { ...@@ -969,7 +969,7 @@ func (dec *Decoder) gobDecodeOpFor(ut *userTypeInfo) (*decOp, int) {
} else { } else {
v = reflect.ValueOf(unsafe.Unreflect(rcvrType, p)) v = reflect.ValueOf(unsafe.Unreflect(rcvrType, p))
} }
state.dec.decodeGobDecoder(state, v, methodIndex(rcvrType, gobDecodeMethodName)) state.dec.decodeGobDecoder(state, v)
} }
return &op, int(ut.indir) return &op, int(ut.indir)
......
...@@ -468,7 +468,7 @@ func (enc *Encoder) encodeInterface(b *bytes.Buffer, iv reflect.Value) { ...@@ -468,7 +468,7 @@ func (enc *Encoder) encodeInterface(b *bytes.Buffer, iv reflect.Value) {
// encGobEncoder encodes a value that implements the GobEncoder interface. // encGobEncoder encodes a value that implements the GobEncoder interface.
// The data is sent as a byte array. // The data is sent as a byte array.
func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value, index int) { func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value) {
// TODO: should we catch panics from the called method? // TODO: should we catch panics from the called method?
// We know it's a GobEncoder, so just call the method directly. // We know it's a GobEncoder, so just call the method directly.
data, err := v.Interface().(GobEncoder).GobEncode() data, err := v.Interface().(GobEncoder).GobEncode()
...@@ -592,17 +592,6 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp ...@@ -592,17 +592,6 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
return &op, indir return &op, indir
} }
// methodIndex returns which method of rt implements the method.
func methodIndex(rt reflect.Type, method string) int {
for i := 0; i < rt.NumMethod(); i++ {
if rt.Method(i).Name == method {
return i
}
}
errorf("internal error: can't find method %s", method)
return 0
}
// gobEncodeOpFor returns the op for a type that is known to implement // gobEncodeOpFor returns the op for a type that is known to implement
// GobEncoder. // GobEncoder.
func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) { func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
...@@ -624,7 +613,7 @@ func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) { ...@@ -624,7 +613,7 @@ func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
v = reflect.ValueOf(unsafe.Unreflect(rt, p)) v = reflect.ValueOf(unsafe.Unreflect(rt, p))
} }
state.update(i) state.update(i)
state.enc.encodeGobEncoder(state.b, v, methodIndex(rt, gobEncodeMethodName)) state.enc.encodeGobEncoder(state.b, v)
} }
return &op, int(ut.encIndir) // encIndir: op will get called with p == address of receiver. return &op, int(ut.encIndir) // encIndir: op will get called with p == address of receiver.
} }
......
...@@ -80,11 +80,6 @@ func validUserType(rt reflect.Type) (ut *userTypeInfo, err os.Error) { ...@@ -80,11 +80,6 @@ func validUserType(rt reflect.Type) (ut *userTypeInfo, err os.Error) {
return return
} }
const (
gobEncodeMethodName = "GobEncode"
gobDecodeMethodName = "GobDecode"
)
var ( var (
gobEncoderInterfaceType = reflect.TypeOf(new(GobEncoder)).Elem() gobEncoderInterfaceType = reflect.TypeOf(new(GobEncoder)).Elem()
gobDecoderInterfaceType = reflect.TypeOf(new(GobDecoder)).Elem() gobDecoderInterfaceType = reflect.TypeOf(new(GobDecoder)).Elem()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment