core/txpool/legacypool: use maps.Keys and maps.Copy (#30091)

pull/30104/head^2
maskpp 2 months ago committed by GitHub
parent b530d8e455
commit 15936c64a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      core/txpool/legacypool/legacypool.go

@ -38,6 +38,7 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
"golang.org/x/exp/maps"
)
const (
@ -1717,7 +1718,7 @@ func (a addressesByHeartbeat) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type accountSet struct {
accounts map[common.Address]struct{}
signer types.Signer
cache *[]common.Address
cache []common.Address
}
// newAccountSet creates a new address set with an associated signer for sender
@ -1765,20 +1766,14 @@ func (as *accountSet) addTx(tx *types.Transaction) {
// reuse. The returned slice should not be changed!
func (as *accountSet) flatten() []common.Address {
if as.cache == nil {
accounts := make([]common.Address, 0, len(as.accounts))
for account := range as.accounts {
accounts = append(accounts, account)
}
as.cache = &accounts
as.cache = maps.Keys(as.accounts)
}
return *as.cache
return as.cache
}
// merge adds all addresses from the 'other' set into 'as'.
func (as *accountSet) merge(other *accountSet) {
for addr := range other.accounts {
as.accounts[addr] = struct{}{}
}
maps.Copy(as.accounts, other.accounts)
as.cache = nil
}

Loading…
Cancel
Save