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 (
"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
})
}