mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
- 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:
parent
7d3e73951f
commit
eef6327046
1 changed files with 3 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue