mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
accounts/keystore: improve deleteByFile
sort.Search requires that the function returns true for all elements after the one it's looking for. Once we have the index, avoid another iteration over the whole slice to remove the element.
This commit is contained in:
parent
d6fa6eabcf
commit
3cfbfdcd4e
1 changed files with 4 additions and 4 deletions
|
|
@ -137,15 +137,15 @@ func (ac *accountCache) delete(removed accounts.Account) {
|
|||
}
|
||||
}
|
||||
|
||||
//deleteByFile removes an account referenced by the given path
|
||||
// deleteByFile removes an account referenced by the given path.
|
||||
func (ac *accountCache) deleteByFile(path string) {
|
||||
ac.mu.Lock()
|
||||
defer ac.mu.Unlock()
|
||||
i := sort.Search(len(ac.all), func(i int) bool { return ac.all[i].URL.Path == path })
|
||||
i := sort.Search(len(ac.all), func(i int) bool { return ac.all[i].URL.Path >= path })
|
||||
|
||||
if i < len(ac.all) {
|
||||
if i < len(ac.all) && ac.all[i].URL.Path == path {
|
||||
removed := ac.all[i]
|
||||
ac.all = removeAccount(ac.all, removed)
|
||||
ac.all = append(ac.all[:i], ac.all[i+1:]...)
|
||||
if ba := removeAccount(ac.byAddr[removed.Address], removed); len(ba) == 0 {
|
||||
delete(ac.byAddr, removed.Address)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue