Skip to content

Commit 1eafd78

Browse files
committed
Unified method parameters
1 parent 5dae7e8 commit 1eafd78

21 files changed

+195
-1646
lines changed

io/array_decoder.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/array_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -63,10 +63,6 @@ func (valdec arrayDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
6363
}
6464
}
6565

66-
func (valdec arrayDecoder) Type() reflect.Type {
67-
return valdec.at.Type1()
68-
}
69-
7066
// makeArrayDecoder returns a arrayDecoder for [N]T.
7167
func makeArrayDecoder(t reflect.Type, decodeElem DecodeHandler) arrayDecoder {
7268
at := reflect2.Type2(t).(*reflect2.UnsafeArrayType)

io/big_decoder.go

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/big_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -201,73 +201,49 @@ func (dec *Decoder) decodeBigRatValue(t reflect.Type, tag byte) big.Rat {
201201
type bigIntValueDecoder struct{}
202202

203203
func (bigIntValueDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
204-
*(*big.Int)(reflect2.PtrOf(p)) = dec.decodeBigIntValue(bigIntValueType, tag)
205-
}
206-
207-
func (bigIntValueDecoder) Type() reflect.Type {
208-
return bigIntValueType
204+
*(*big.Int)(reflect2.PtrOf(p)) = dec.decodeBigIntValue(reflect.TypeOf(p).Elem(), tag)
209205
}
210206

211207
// bigIntDecoder is the implementation of ValueDecoder for *big.Int.
212208
type bigIntDecoder struct{}
213209

214210
func (bigIntDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
215-
*(**big.Int)(reflect2.PtrOf(p)) = dec.decodeBigInt(bigIntType, tag)
216-
}
217-
218-
func (bigIntDecoder) Type() reflect.Type {
219-
return bigIntType
211+
*(**big.Int)(reflect2.PtrOf(p)) = dec.decodeBigInt(reflect.TypeOf(p).Elem(), tag)
220212
}
221213

222214
// bigFloatValueDecoder is the implementation of ValueDecoder for big.Float.
223215
type bigFloatValueDecoder struct{}
224216

225217
func (bigFloatValueDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
226-
*(*big.Float)(reflect2.PtrOf(p)) = dec.decodeBigFloatValue(bigFloatValueType, tag)
227-
}
228-
229-
func (bigFloatValueDecoder) Type() reflect.Type {
230-
return bigFloatValueType
218+
*(*big.Float)(reflect2.PtrOf(p)) = dec.decodeBigFloatValue(reflect.TypeOf(p).Elem(), tag)
231219
}
232220

233221
// bigFloatDecoder is the implementation of ValueDecoder for *big.Float.
234222
type bigFloatDecoder struct{}
235223

236224
func (bigFloatDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
237-
*(**big.Float)(reflect2.PtrOf(p)) = dec.decodeBigFloat(bigFloatType, tag)
238-
}
239-
240-
func (bigFloatDecoder) Type() reflect.Type {
241-
return bigFloatType
225+
*(**big.Float)(reflect2.PtrOf(p)) = dec.decodeBigFloat(reflect.TypeOf(p).Elem(), tag)
242226
}
243227

244228
// bigRatValueDecoder is the implementation of ValueDecoder for big.Rat.
245229
type bigRatValueDecoder struct{}
246230

247231
func (bigRatValueDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
248-
*(*big.Rat)(reflect2.PtrOf(p)) = dec.decodeBigRatValue(bigRatValueType, tag)
249-
}
250-
251-
func (bigRatValueDecoder) Type() reflect.Type {
252-
return bigRatValueType
232+
*(*big.Rat)(reflect2.PtrOf(p)) = dec.decodeBigRatValue(reflect.TypeOf(p).Elem(), tag)
253233
}
254234

255235
// bigRatDecoder is the implementation of ValueDecoder for big.Rat/*big.Rat.
256236
type bigRatDecoder struct{}
257237

258238
func (bigRatDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
259-
*(**big.Rat)(reflect2.PtrOf(p)) = dec.decodeBigRat(bigRatType, tag)
260-
}
261-
262-
func (bigRatDecoder) Type() reflect.Type {
263-
return bigRatType
239+
*(**big.Rat)(reflect2.PtrOf(p)) = dec.decodeBigRat(reflect.TypeOf(p).Elem(), tag)
264240
}
265241

266242
func init() {
267-
RegisterValueDecoder(bigIntDecoder{})
268-
RegisterValueDecoder(bigFloatDecoder{})
269-
RegisterValueDecoder(bigRatDecoder{})
270-
RegisterValueDecoder(bigIntValueDecoder{})
271-
RegisterValueDecoder(bigFloatValueDecoder{})
272-
RegisterValueDecoder(bigRatValueDecoder{})
243+
registerValueDecoder(bigIntType, bigIntDecoder{})
244+
registerValueDecoder(bigFloatType, bigFloatDecoder{})
245+
registerValueDecoder(bigRatType, bigRatDecoder{})
246+
registerValueDecoder(bigIntValueType, bigIntValueDecoder{})
247+
registerValueDecoder(bigFloatValueType, bigFloatValueDecoder{})
248+
registerValueDecoder(bigRatValueType, bigRatValueDecoder{})
273249
}

io/bool_decoder.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/bool_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -79,10 +79,6 @@ func (valdec boolDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
7979
*(*bool)(reflect2.PtrOf(p)) = dec.decodeBool(valdec.t, tag)
8080
}
8181

82-
func (valdec boolDecoder) Type() reflect.Type {
83-
return valdec.t
84-
}
85-
8682
// boolPtrDecoder is the implementation of ValueDecoder for *bool.
8783
type boolPtrDecoder struct {
8884
t reflect.Type
@@ -91,7 +87,3 @@ type boolPtrDecoder struct {
9187
func (valdec boolPtrDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
9288
*(**bool)(reflect2.PtrOf(p)) = dec.decodeBoolPtr(valdec.t, tag)
9389
}
94-
95-
func (valdec boolPtrDecoder) Type() reflect.Type {
96-
return valdec.t
97-
}

io/bytes_decoder.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/bytes_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -92,10 +92,6 @@ func (valdec bytesDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
9292
*(*[]byte)(reflect2.PtrOf(p)) = dec.decodeBytes(valdec.t, tag)
9393
}
9494

95-
func (valdec bytesDecoder) Type() reflect.Type {
96-
return valdec.t
97-
}
98-
9995
// bytesPtrDecoder is the implementation of ValueDecoder for *[]byte.
10096
type bytesPtrDecoder struct {
10197
t reflect.Type
@@ -105,11 +101,7 @@ func (valdec bytesPtrDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
105101
*(**[]byte)(reflect2.PtrOf(p)) = dec.decodeBytesPtr(valdec.t, tag)
106102
}
107103

108-
func (valdec bytesPtrDecoder) Type() reflect.Type {
109-
return valdec.t
110-
}
111-
112104
func init() {
113-
RegisterValueDecoder(bytesDecoder{bytesType})
114-
RegisterValueDecoder(bytesPtrDecoder{bytesPtrType})
105+
registerValueDecoder(bytesType, bytesDecoder{bytesType})
106+
registerValueDecoder(bytesPtrType, bytesPtrDecoder{bytesPtrType})
115107
}

io/complex_decoder.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/complex_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -122,10 +122,6 @@ func (valdec complex64Decoder) Decode(dec *Decoder, p interface{}, tag byte) {
122122
*(*complex64)(reflect2.PtrOf(p)) = dec.decodeComplex64(valdec.t, tag)
123123
}
124124

125-
func (valdec complex64Decoder) Type() reflect.Type {
126-
return valdec.t
127-
}
128-
129125
// complex64PtrDecoder is the implementation of ValueDecoder for *complex64.
130126
type complex64PtrDecoder struct {
131127
t reflect.Type
@@ -135,10 +131,6 @@ func (valdec complex64PtrDecoder) Decode(dec *Decoder, p interface{}, tag byte)
135131
*(**complex64)(reflect2.PtrOf(p)) = dec.decodeComplex64Ptr(valdec.t, tag)
136132
}
137133

138-
func (valdec complex64PtrDecoder) Type() reflect.Type {
139-
return valdec.t
140-
}
141-
142134
// complex128Decoder is the implementation of ValueDecoder for complex128.
143135
type complex128Decoder struct {
144136
t reflect.Type
@@ -148,10 +140,6 @@ func (valdec complex128Decoder) Decode(dec *Decoder, p interface{}, tag byte) {
148140
*(*complex128)(reflect2.PtrOf(p)) = dec.decodeComplex128(valdec.t, tag)
149141
}
150142

151-
func (valdec complex128Decoder) Type() reflect.Type {
152-
return valdec.t
153-
}
154-
155143
// complex128PtrDecoder is the implementation of ValueDecoder for *complex128.
156144
type complex128PtrDecoder struct {
157145
t reflect.Type
@@ -160,7 +148,3 @@ type complex128PtrDecoder struct {
160148
func (valdec complex128PtrDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
161149
*(**complex128)(reflect2.PtrOf(p)) = dec.decodeComplex128Ptr(valdec.t, tag)
162150
}
163-
164-
func (valdec complex128PtrDecoder) Type() reflect.Type {
165-
return valdec.t
166-
}

io/decode_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func stringPtrDecode(dec *Decoder, t reflect.Type, p unsafe.Pointer) {
194194
}
195195

196196
func otherDecode(t reflect.Type) DecodeHandler {
197-
valdec := GetValueDecoder(t)
197+
valdec := getValueDecoder(t)
198198
t2 := reflect2.Type2(t)
199199
return func(dec *Decoder, t reflect.Type, p unsafe.Pointer) {
200200
valdec.Decode(dec, t2.PackEFace(p), dec.NextByte())
@@ -203,7 +203,7 @@ func otherDecode(t reflect.Type) DecodeHandler {
203203

204204
// GetDecodeHandler for specified type.
205205
func GetDecodeHandler(t reflect.Type) DecodeHandler {
206-
if getValueDecoder(t) == nil {
206+
if getRegisteredValueDecoder(t) == nil {
207207
kind := t.Kind()
208208
if decode := decodeHandlers[kind]; decode != nil {
209209
return decode

io/decoder.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,10 @@ func (dec *Decoder) decode(p interface{}, tag byte) {
221221
return
222222
}
223223
t := reflect.TypeOf(p).Elem()
224-
switch t.Kind() {
225-
case reflect.Map:
226-
if dec.fastDecodeMap(t, p, tag) {
227-
return
228-
}
229-
case reflect.Ptr:
230-
if dec.fastDecodePtr(p, tag) {
231-
return
232-
}
233-
case reflect.Slice:
234-
if dec.fastDecodeSlice(p, tag) {
235-
return
236-
}
224+
if t.Kind() == reflect.Ptr && dec.fastDecodePtr(p, tag) {
225+
return
237226
}
238-
if valdec := GetValueDecoder(t); valdec != nil {
227+
if valdec := getValueDecoder(t); valdec != nil {
239228
valdec.Decode(dec, p, tag)
240229
}
241230
}

io/float_decoder.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/float_decoder.go |
88
| |
9-
| LastModified: May 14, 2021 |
9+
| LastModified: Jun 5, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -129,10 +129,6 @@ func (valdec float32Decoder) Decode(dec *Decoder, p interface{}, tag byte) {
129129
*(*float32)(reflect2.PtrOf(p)) = dec.decodeFloat32(valdec.t, tag)
130130
}
131131

132-
func (valdec float32Decoder) Type() reflect.Type {
133-
return valdec.t
134-
}
135-
136132
// float32PtrDecoder is the implementation of ValueDecoder for *float32.
137133
type float32PtrDecoder struct {
138134
t reflect.Type
@@ -142,10 +138,6 @@ func (valdec float32PtrDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
142138
*(**float32)(reflect2.PtrOf(p)) = dec.decodeFloat32Ptr(valdec.t, tag)
143139
}
144140

145-
func (valdec float32PtrDecoder) Type() reflect.Type {
146-
return valdec.t
147-
}
148-
149141
// float64Decoder is the implementation of ValueDecoder for float64.
150142
type float64Decoder struct {
151143
t reflect.Type
@@ -155,10 +147,6 @@ func (valdec float64Decoder) Decode(dec *Decoder, p interface{}, tag byte) {
155147
*(*float64)(reflect2.PtrOf(p)) = dec.decodeFloat64(valdec.t, tag)
156148
}
157149

158-
func (valdec float64Decoder) Type() reflect.Type {
159-
return valdec.t
160-
}
161-
162150
// float64PtrDecoder is the implementation of ValueDecoder for *float64.
163151
type float64PtrDecoder struct {
164152
t reflect.Type
@@ -167,7 +155,3 @@ type float64PtrDecoder struct {
167155
func (valdec float64PtrDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
168156
*(**float64)(reflect2.PtrOf(p)) = dec.decodeFloat64Ptr(valdec.t, tag)
169157
}
170-
171-
func (valdec float64PtrDecoder) Type() reflect.Type {
172-
return valdec.t
173-
}

0 commit comments

Comments
 (0)