mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-10 06:54:26 +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 (
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue