mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 04:06:44 +00:00
accounts: use slices.Delete
This commit is contained in:
parent
7fbadaa8f5
commit
5ce4e0ff37
1 changed files with 8 additions and 8 deletions
|
|
@ -18,6 +18,7 @@ package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -254,13 +255,12 @@ func merge(slice []Wallet, wallets ...Wallet) []Wallet {
|
||||||
// drop is the counterpart of merge, which looks up wallets from within the sorted
|
// drop is the counterpart of merge, which looks up wallets from within the sorted
|
||||||
// cache and removes the ones specified.
|
// cache and removes the ones specified.
|
||||||
func drop(slice []Wallet, wallets ...Wallet) []Wallet {
|
func drop(slice []Wallet, wallets ...Wallet) []Wallet {
|
||||||
for _, wallet := range wallets {
|
remove := make(map[URL]struct{}, len(wallets))
|
||||||
n := sort.Search(len(slice), func(i int) bool { return slice[i].URL().Cmp(wallet.URL()) >= 0 })
|
for _, w := range wallets {
|
||||||
if n == len(slice) || slice[n].URL().Cmp(wallet.URL()) != 0 {
|
remove[w.URL()] = struct{}{}
|
||||||
// Wallet not found, may happen during startup
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
slice = append(slice[:n], slice[n+1:]...)
|
|
||||||
}
|
}
|
||||||
return slice
|
return slices.DeleteFunc(slice, func(w Wallet) bool {
|
||||||
|
_, ok := remove[w.URL()]
|
||||||
|
return ok
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue