all: combine key iterators and sorting in one step

This commit is contained in:
Martin Holst Swende 2024-10-08 10:21:22 +02:00 committed by Felix Lange
parent 49ef93ea1c
commit 02ee623548
3 changed files with 4 additions and 10 deletions

View file

@ -54,8 +54,7 @@ func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index map[common.A
// Populate the heap in account sort order. Not really needed in practice,
// but it makes the heap initialization deterministic and less annoying to
// test in unit tests.
heap.addrs = slices.Collect(maps.Keys(index))
slices.SortFunc(heap.addrs, common.Address.Cmp)
heap.addrs = slices.SortedFunc(maps.Keys(index), common.Address.Cmp)
for i, addr := range heap.addrs {
heap.index[addr] = i
}

View file

@ -323,8 +323,7 @@ func (s *DistinctNetSet) key(ip netip.Addr) netip.Prefix {
// String implements fmt.Stringer
func (s DistinctNetSet) String() string {
keys := slices.Collect(maps.Keys(s.members))
slices.SortFunc(keys, func(a, b netip.Prefix) int {
keys := slices.SortedFunc(maps.Keys(s.members), func(a, b netip.Prefix) int {
return strings.Compare(a.String(), b.String())
})

View file

@ -250,15 +250,11 @@ type history struct {
// newHistory constructs the state history object with provided state change set.
func newHistory(root common.Hash, parent common.Hash, block uint64, accounts map[common.Address][]byte, storages map[common.Address]map[common.Hash][]byte, rawStorageKey bool) *history {
var (
accountList = slices.Collect(maps.Keys(accounts))
accountList = slices.SortedFunc(maps.Keys(accounts), common.Address.Cmp)
storageList = make(map[common.Address][]common.Hash)
)
slices.SortFunc(accountList, common.Address.Cmp)
for addr, slots := range storages {
slist := slices.Collect(maps.Keys(slots))
slices.SortFunc(slist, common.Hash.Cmp)
storageList[addr] = slist
storageList[addr] = slices.SortedFunc(maps.Keys(slots), common.Hash.Cmp)
}
version := historyVersion
if !rawStorageKey {