core/state: move slices.SortFunc out of a for loop

This commit is contained in:
ericxtheodore 2025-07-29 17:47:14 +08:00 committed by GitHub
parent a56558d092
commit f7eae65763
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -145,7 +145,7 @@ func (al *accessList) Equal(other *accessList) bool {
// PrettyPrint prints the contents of the access list in a human-readable form
func (al *accessList) PrettyPrint() string {
out := new(strings.Builder)
var sortedAddrs []common.Address
sortedAddrs := make([]common.Address, 0, len(al.addresses))
for addr := range al.addresses {
sortedAddrs = append(sortedAddrs, addr)
}

View file

@ -70,16 +70,16 @@ func (t transientStorage) Copy() transientStorage {
// PrettyPrint prints the contents of the access list in a human-readable form
func (t transientStorage) PrettyPrint() string {
out := new(strings.Builder)
var sortedAddrs []common.Address
sortedAddrs := make([]common.Address, 0, len(t))
for addr := range t {
sortedAddrs = append(sortedAddrs, addr)
slices.SortFunc(sortedAddrs, common.Address.Cmp)
}
slices.SortFunc(sortedAddrs, common.Address.Cmp)
for _, addr := range sortedAddrs {
fmt.Fprintf(out, "%#x:", addr)
var sortedKeys []common.Hash
storage := t[addr]
sortedKeys = make([]common.Hash, 0, len(storage))
for key := range storage {
sortedKeys = append(sortedKeys, key)
}