aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-12-20 18:59:35 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-02-23 16:27:05 +0100
commit6287203beb84d03c4a72c6b96e66cea7ed02c5e3 (patch)
tree06e05ed3cb5a271f48548335d42fc784f475750d
parenttunnel: deduplicate addresses from config (diff)
downloadwireguard-windows-6287203beb84d03c4a72c6b96e66cea7ed02c5e3.tar.xz
wireguard-windows-6287203beb84d03c4a72c6b96e66cea7ed02c5e3.zip
ui: reduce iteration nesting when removing old tunnels
Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--ui/listview.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/ui/listview.go b/ui/listview.go
index e9ecb2f8..60679579 100644
--- a/ui/listview.go
+++ b/ui/listview.go
@@ -225,21 +225,14 @@ func (tv *ListView) Load(asyncUI bool) {
for _, tunnel := range tunnels {
newTunnels[tunnel] = true
}
- for _, tunnel := range tv.model.tunnels {
+ for i := len(tv.model.tunnels); i > 0; {
+ i--
+ tunnel := tv.model.tunnels[i]
oldTunnels[tunnel] = true
- }
-
- for tunnel := range oldTunnels {
if !newTunnels[tunnel] {
- for i, t := range tv.model.tunnels {
- // TODO: this is inefficient. Use a map here instead.
- if t.Name == tunnel.Name {
- tv.model.tunnels = append(tv.model.tunnels[:i], tv.model.tunnels[i+1:]...)
- tv.model.PublishRowsRemoved(i, i) // TODO: Do we have to call that everytime or can we pass a range?
- delete(tv.model.lastObservedState, t)
- break
- }
- }
+ tv.model.tunnels = append(tv.model.tunnels[:i], tv.model.tunnels[i+1:]...)
+ tv.model.PublishRowsRemoved(i, i) // TODO: Do we have to call that everytime or can we pass a range?
+ delete(tv.model.lastObservedState, tunnel)
}
}
didAdd := false