mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46: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 (
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"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
|
||||
// cache and removes the ones specified.
|
||||
func drop(slice []Wallet, wallets ...Wallet) []Wallet {
|
||||
for _, wallet := range wallets {
|
||||
n := sort.Search(len(slice), func(i int) bool { return slice[i].URL().Cmp(wallet.URL()) >= 0 })
|
||||
if n == len(slice) || slice[n].URL().Cmp(wallet.URL()) != 0 {
|
||||
// Wallet not found, may happen during startup
|
||||
continue
|
||||
}
|
||||
slice = append(slice[:n], slice[n+1:]...)
|
||||
remove := make(map[URL]struct{}, len(wallets))
|
||||
for _, w := range wallets {
|
||||
remove[w.URL()] = struct{}{}
|
||||
}
|
||||
return slice
|
||||
return slices.DeleteFunc(slice, func(w Wallet) bool {
|
||||
_, ok := remove[w.URL()]
|
||||
return ok
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue