Skip to content

Commit d14d4d2

Browse files
core/state: improve PrettyPrint function (#32293)
1 parent a56558d commit d14d4d2

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

core/state/access_list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ func (al *accessList) Equal(other *accessList) bool {
145145
// PrettyPrint prints the contents of the access list in a human-readable form
146146
func (al *accessList) PrettyPrint() string {
147147
out := new(strings.Builder)
148-
var sortedAddrs []common.Address
149-
for addr := range al.addresses {
150-
sortedAddrs = append(sortedAddrs, addr)
151-
}
148+
sortedAddrs := slices.Collect(maps.Keys(al.addresses))
152149
slices.SortFunc(sortedAddrs, common.Address.Cmp)
153150
for _, addr := range sortedAddrs {
154151
idx := al.addresses[addr]

core/state/transient_storage.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package state
1818

1919
import (
2020
"fmt"
21+
"maps"
2122
"slices"
2223
"strings"
2324

@@ -70,19 +71,13 @@ func (t transientStorage) Copy() transientStorage {
7071
// PrettyPrint prints the contents of the access list in a human-readable form
7172
func (t transientStorage) PrettyPrint() string {
7273
out := new(strings.Builder)
73-
var sortedAddrs []common.Address
74-
for addr := range t {
75-
sortedAddrs = append(sortedAddrs, addr)
76-
slices.SortFunc(sortedAddrs, common.Address.Cmp)
77-
}
74+
sortedAddrs := slices.Collect(maps.Keys(t))
75+
slices.SortFunc(sortedAddrs, common.Address.Cmp)
7876

7977
for _, addr := range sortedAddrs {
8078
fmt.Fprintf(out, "%#x:", addr)
81-
var sortedKeys []common.Hash
8279
storage := t[addr]
83-
for key := range storage {
84-
sortedKeys = append(sortedKeys, key)
85-
}
80+
sortedKeys := slices.Collect(maps.Keys(storage))
8681
slices.SortFunc(sortedKeys, common.Hash.Cmp)
8782
for _, key := range sortedKeys {
8883
fmt.Fprintf(out, " %X : %X\n", key, storage[key])

0 commit comments

Comments
 (0)