From f7eae65763628ad7367cd7ce55a5ef738e5b3af2 Mon Sep 17 00:00:00 2001 From: ericxtheodore Date: Tue, 29 Jul 2025 17:47:14 +0800 Subject: [PATCH] core/state: move slices.SortFunc out of a for loop --- core/state/access_list.go | 2 +- core/state/transient_storage.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/state/access_list.go b/core/state/access_list.go index a58c2b20ea..1e2d840e6a 100644 --- a/core/state/access_list.go +++ b/core/state/access_list.go @@ -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) } diff --git a/core/state/transient_storage.go b/core/state/transient_storage.go index e63db39eba..8b5ae67fd5 100644 --- a/core/state/transient_storage.go +++ b/core/state/transient_storage.go @@ -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) }