Skip to content

Commit f9f85d0

Browse files
authored
core: use reflect.TypeFor (#32320)
golang/go#60088
1 parent 2e3971a commit f9f85d0

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

core/forkid/forkid.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,8 @@ func checksumToBytes(hash uint32) [4]byte {
241241
// them, one for the block number based forks and the second for the timestamps.
242242
func gatherForks(config *params.ChainConfig, genesis uint64) ([]uint64, []uint64) {
243243
// Gather all the fork block numbers via reflection
244-
kind := reflect.TypeOf(params.ChainConfig{})
244+
kind := reflect.TypeFor[params.ChainConfig]()
245245
conf := reflect.ValueOf(config).Elem()
246-
x := uint64(0)
247246
var (
248247
forksByBlock []uint64
249248
forksByTime []uint64
@@ -258,12 +257,12 @@ func gatherForks(config *params.ChainConfig, genesis uint64) ([]uint64, []uint64
258257
}
259258

260259
// Extract the fork rule block number or timestamp and aggregate it
261-
if field.Type == reflect.TypeOf(&x) {
260+
if field.Type == reflect.TypeFor[*uint64]() {
262261
if rule := conf.Field(i).Interface().(*uint64); rule != nil {
263262
forksByTime = append(forksByTime, *rule)
264263
}
265264
}
266-
if field.Type == reflect.TypeOf(new(big.Int)) {
265+
if field.Type == reflect.TypeFor[*big.Int]() {
267266
if rule := conf.Field(i).Interface().(*big.Int); rule != nil {
268267
forksByBlock = append(forksByBlock, rule.Uint64())
269268
}

core/tracing/journal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func newTracerAllHooks() *tracerAllHooks {
293293
t := &tracerAllHooks{hooksCalled: make(map[string]bool)}
294294
// Initialize all hooks to false. We will use this to
295295
// get total count of hooks.
296-
hooksType := reflect.TypeOf((*Hooks)(nil)).Elem()
296+
hooksType := reflect.TypeFor[Hooks]()
297297
for i := 0; i < hooksType.NumField(); i++ {
298298
t.hooksCalled[hooksType.Field(i).Name] = false
299299
}

core/types/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (h *Header) Hash() common.Hash {
128128
return rlpHash(h)
129129
}
130130

131-
var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size())
131+
var headerSize = common.StorageSize(reflect.TypeFor[Header]().Size())
132132

133133
// Size returns the approximate memory used by all internal contents. It is used
134134
// to approximate and limit the memory consumption of various caches.

core/types/withdrawal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Withdrawals []*Withdrawal
4949
// Len returns the length of s.
5050
func (s Withdrawals) Len() int { return len(s) }
5151

52-
var withdrawalSize = int(reflect.TypeOf(Withdrawal{}).Size())
52+
var withdrawalSize = int(reflect.TypeFor[Withdrawal]().Size())
5353

5454
func (s Withdrawals) Size() int {
5555
return withdrawalSize * len(s)

0 commit comments

Comments
 (0)