From f7eae65763628ad7367cd7ce55a5ef738e5b3af2 Mon Sep 17 00:00:00 2001 From: ericxtheodore Date: Tue, 29 Jul 2025 17:47:14 +0800 Subject: [PATCH 1/4] 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 a58c2b20ea9..1e2d840e6aa 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 e63db39ebab..8b5ae67fd53 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) } From cd09948040284ada6811354f45d73e0233f0875d Mon Sep 17 00:00:00 2001 From: ericxtheodore Date: Tue, 29 Jul 2025 17:58:25 +0800 Subject: [PATCH 2/4] fix --- core/state/transient_storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/state/transient_storage.go b/core/state/transient_storage.go index 8b5ae67fd53..f55c694af47 100644 --- a/core/state/transient_storage.go +++ b/core/state/transient_storage.go @@ -79,7 +79,7 @@ func (t transientStorage) PrettyPrint() string { for _, addr := range sortedAddrs { fmt.Fprintf(out, "%#x:", addr) storage := t[addr] - sortedKeys = make([]common.Hash, 0, len(storage)) + sortedKeys := make([]common.Hash, 0, len(storage)) for key := range storage { sortedKeys = append(sortedKeys, key) } From 0029554f8cffca31f041e0d198dafa0e95293781 Mon Sep 17 00:00:00 2001 From: ericxtheodore Date: Tue, 29 Jul 2025 20:18:55 +0800 Subject: [PATCH 3/4] use builtin slices.Collect --- core/state/access_list.go | 5 +---- core/state/transient_storage.go | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/state/access_list.go b/core/state/access_list.go index 1e2d840e6aa..e3f17388648 100644 --- a/core/state/access_list.go +++ b/core/state/access_list.go @@ -145,10 +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) - sortedAddrs := make([]common.Address, 0, len(al.addresses)) - for addr := range al.addresses { - sortedAddrs = append(sortedAddrs, addr) - } + sortedAddrs := slices.Collect(maps.Keys(al.addresses)) slices.SortFunc(sortedAddrs, common.Address.Cmp) for _, addr := range sortedAddrs { idx := al.addresses[addr] diff --git a/core/state/transient_storage.go b/core/state/transient_storage.go index f55c694af47..edb2d4810e9 100644 --- a/core/state/transient_storage.go +++ b/core/state/transient_storage.go @@ -18,6 +18,7 @@ package state import ( "fmt" + "maps" "slices" "strings" @@ -70,10 +71,7 @@ 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) - sortedAddrs := make([]common.Address, 0, len(t)) - for addr := range t { - sortedAddrs = append(sortedAddrs, addr) - } + sortedAddrs := slices.Collect(maps.Keys(t)) slices.SortFunc(sortedAddrs, common.Address.Cmp) for _, addr := range sortedAddrs { From c608c9be4c00fa56308b320bbafe5ec7aecfd3b9 Mon Sep 17 00:00:00 2001 From: ericxtheodore Date: Tue, 29 Jul 2025 20:26:29 +0800 Subject: [PATCH 4/4] more --- core/state/transient_storage.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/state/transient_storage.go b/core/state/transient_storage.go index edb2d4810e9..3bb49554255 100644 --- a/core/state/transient_storage.go +++ b/core/state/transient_storage.go @@ -77,10 +77,7 @@ func (t transientStorage) PrettyPrint() string { for _, addr := range sortedAddrs { fmt.Fprintf(out, "%#x:", addr) storage := t[addr] - sortedKeys := make([]common.Hash, 0, len(storage)) - for key := range storage { - sortedKeys = append(sortedKeys, key) - } + sortedKeys := slices.Collect(maps.Keys(storage)) slices.SortFunc(sortedKeys, common.Hash.Cmp) for _, key := range sortedKeys { fmt.Fprintf(out, " %X : %X\n", key, storage[key])