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

- slice and map are reference types, we can use themselves as pointers.
- Use maps.Keys and maps.Copy simplify code.
This commit is contained in:
Daniel Liu 2026-03-17 13:47:44 +08:00 committed by GitHub
parent 7d3e73951f
commit eef6327046
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,6 +20,7 @@ package legacypool
import (
"errors"
"fmt"
"maps"
"math"
"math/big"
"slices"
@ -1974,10 +1975,7 @@ 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)
}
accounts := slices.Collect(maps.Keys(as.accounts))
as.cache = &accounts
}
return *as.cache
@ -1985,9 +1983,7 @@ func (as *accountSet) flatten() []common.Address {
// 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
}