accounts: use slices.Delete

This commit is contained in:
Felix Lange 2026-07-02 18:09:29 +02:00
parent 7fbadaa8f5
commit 5ce4e0ff37

View file

@ -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 slices.DeleteFunc(slice, func(w Wallet) bool {
} _, ok := remove[w.URL()]
return slice return ok
})
} }