Skip to content

Commit 4e7bc2b

Browse files
cuiweixiefjl
andauthored
rlp: use reflect.TypeFor (#32317)
Co-authored-by: Felix Lange <[email protected]>
1 parent bd6797e commit 4e7bc2b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

rlp/decode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ func addErrorContext(err error, ctx string) error {
148148
}
149149

150150
var (
151-
decoderInterface = reflect.TypeOf(new(Decoder)).Elem()
152-
bigInt = reflect.TypeOf(big.Int{})
153-
u256Int = reflect.TypeOf(uint256.Int{})
151+
decoderInterface = reflect.TypeFor[Decoder]()
152+
bigInt = reflect.TypeFor[big.Int]()
153+
u256Int = reflect.TypeFor[uint256.Int]()
154154
)
155155

156156
func makeDecoder(typ reflect.Type, tags rlpstruct.Tags) (dec decoder, err error) {
@@ -512,7 +512,7 @@ func makeNilPtrDecoder(etype reflect.Type, etypeinfo *typeinfo, ts rlpstruct.Tag
512512
}
513513
}
514514

515-
var ifsliceType = reflect.TypeOf([]interface{}{})
515+
var ifsliceType = reflect.TypeFor[[]any]()
516516

517517
func decodeInterface(s *Stream, val reflect.Value) error {
518518
if val.Type().NumMethod() != 0 {

rlp/encode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func puthead(buf []byte, smalltag, largetag byte, size uint64) int {
133133
return sizesize + 1
134134
}
135135

136-
var encoderInterface = reflect.TypeOf(new(Encoder)).Elem()
136+
var encoderInterface = reflect.TypeFor[Encoder]()
137137

138138
// makeWriter creates a writer function for the given type.
139139
func makeWriter(typ reflect.Type, ts rlpstruct.Tags) (writer, error) {

rlp/raw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
// not verify whether the content of RawValues is valid RLP.
2727
type RawValue []byte
2828

29-
var rawValueType = reflect.TypeOf(RawValue{})
29+
var rawValueType = reflect.TypeFor[RawValue]()
3030

3131
// StringSize returns the encoded size of a string.
3232
func StringSize(s string) uint64 {

0 commit comments

Comments
 (0)