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 ( import (
"errors" "errors"
"fmt" "fmt"
"maps"
"math" "math"
"math/big" "math/big"
"slices" "slices"
@ -1974,10 +1975,7 @@ func (as *accountSet) addTx(tx *types.Transaction) {
// reuse. The returned slice should not be changed! // reuse. The returned slice should not be changed!
func (as *accountSet) flatten() []common.Address { func (as *accountSet) flatten() []common.Address {
if as.cache == nil { if as.cache == nil {
accounts := make([]common.Address, 0, len(as.accounts)) accounts := slices.Collect(maps.Keys(as.accounts))
for account := range as.accounts {
accounts = append(accounts, account)
}
as.cache = &accounts as.cache = &accounts
} }
return *as.cache return *as.cache
@ -1985,9 +1983,7 @@ func (as *accountSet) flatten() []common.Address {
// merge adds all addresses from the 'other' set into 'as'. // merge adds all addresses from the 'other' set into 'as'.
func (as *accountSet) merge(other *accountSet) { func (as *accountSet) merge(other *accountSet) {
for addr := range other.accounts { maps.Copy(as.accounts, other.accounts)
as.accounts[addr] = struct{}{}
}
as.cache = nil as.cache = nil
} }