mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
use golang.org/x/exp/maps
This commit is contained in:
parent
3158ab1a27
commit
08d8a68e85
1 changed files with 13 additions and 11 deletions
|
|
@ -19,7 +19,6 @@ package pathdb
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"maps"
|
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -28,6 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// counter helps in tracking items and their corresponding sizes.
|
// counter helps in tracking items and their corresponding sizes.
|
||||||
|
|
@ -174,7 +174,8 @@ func (s *stateSet) accountList() []common.Hash {
|
||||||
s.listLock.Lock()
|
s.listLock.Lock()
|
||||||
defer s.listLock.Unlock()
|
defer s.listLock.Unlock()
|
||||||
|
|
||||||
list = slices.SortedFunc(maps.Keys(s.accountData), common.Hash.Cmp)
|
list = maps.Keys(s.accountData)
|
||||||
|
slices.SortFunc(list, common.Hash.Cmp)
|
||||||
s.accountListSorted = list
|
s.accountListSorted = list
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +205,8 @@ func (s *stateSet) storageList(accountHash common.Hash) []common.Hash {
|
||||||
s.listLock.Lock()
|
s.listLock.Lock()
|
||||||
defer s.listLock.Unlock()
|
defer s.listLock.Unlock()
|
||||||
|
|
||||||
list := slices.SortedFunc(maps.Keys(s.storageData[accountHash]), common.Hash.Cmp)
|
list := maps.Keys(s.storageData[accountHash])
|
||||||
|
slices.SortFunc(list, common.Hash.Cmp)
|
||||||
s.storageListSorted[accountHash] = list
|
s.storageListSorted[accountHash] = list
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
@ -339,8 +341,8 @@ func (s *stateSet) encode(w io.Writer) error {
|
||||||
Accounts [][]byte
|
Accounts [][]byte
|
||||||
}
|
}
|
||||||
if err := rlp.Encode(w, accounts{
|
if err := rlp.Encode(w, accounts{
|
||||||
AddrHashes: slices.Collect(maps.Keys(s.accountData)),
|
AddrHashes: maps.Keys(s.accountData),
|
||||||
Accounts: slices.Collect(maps.Values(s.accountData)),
|
Accounts: maps.Values(s.accountData),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -354,8 +356,8 @@ func (s *stateSet) encode(w io.Writer) error {
|
||||||
for addrHash, slots := range s.storageData {
|
for addrHash, slots := range s.storageData {
|
||||||
storages = append(storages, Storage{
|
storages = append(storages, Storage{
|
||||||
AddrHash: addrHash,
|
AddrHash: addrHash,
|
||||||
Keys: slices.Collect(maps.Keys(slots)),
|
Keys: maps.Keys(slots),
|
||||||
Vals: slices.Collect(maps.Values(slots)),
|
Vals: maps.Values(slots),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return rlp.Encode(w, storages)
|
return rlp.Encode(w, storages)
|
||||||
|
|
@ -491,8 +493,8 @@ func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
||||||
Accounts [][]byte
|
Accounts [][]byte
|
||||||
}
|
}
|
||||||
if err := rlp.Encode(w, Accounts{
|
if err := rlp.Encode(w, Accounts{
|
||||||
Addresses: slices.Collect(maps.Keys(s.accountOrigin)),
|
Addresses: maps.Keys(s.accountOrigin),
|
||||||
Accounts: slices.Collect(maps.Values(s.accountOrigin)),
|
Accounts: maps.Values(s.accountOrigin),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -506,8 +508,8 @@ func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
||||||
for address, slots := range s.storageOrigin {
|
for address, slots := range s.storageOrigin {
|
||||||
storages = append(storages, Storage{
|
storages = append(storages, Storage{
|
||||||
Address: address,
|
Address: address,
|
||||||
Keys: slices.Collect(maps.Keys(slots)),
|
Keys: maps.Keys(slots),
|
||||||
Vals: slices.Collect(maps.Values(slots)),
|
Vals: maps.Values(slots),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return rlp.Encode(w, storages)
|
return rlp.Encode(w, storages)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue