aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/confview.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-08 22:06:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-08 22:06:13 +0200
commitf72fc2936a19fb06034f10a71286121f2fbcee6f (patch)
treefcc9af5807f4d483725bf38cd7c50afbcae604bc /ui/confview.go
parentui: fix ctrl+a on list invalidating list (diff)
downloadwireguard-windows-f72fc2936a19fb06034f10a71286121f2fbcee6f.tar.xz
wireguard-windows-f72fc2936a19fb06034f10a71286121f2fbcee6f.zip
ui: confview: recycle more peerviews
If there are no similarities between one peer list and the next, then ordering between peers can't possibly matter, so recycle all of the peerviews that we can. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--ui/confview.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/ui/confview.go b/ui/confview.go
index 5f4c4d96..ca14abea 100644
--- a/ui/confview.go
+++ b/ui/confview.go
@@ -566,11 +566,31 @@ func (cv *ConfView) setTunnel(tunnel *service.Tunnel, config *conf.Config, state
cv.interfaze.status.update(state)
cv.interfaze.toggleActive.update(state)
inverse := make(map[*peerView]bool, len(cv.peers))
+ all := make([]*peerView, 0, len(cv.peers))
for _, pv := range cv.peers {
inverse[pv] = true
+ all = append(all, pv)
}
+ someMatch := false
for _, peer := range config.Peers {
- if pv := cv.peers[peer.PublicKey]; pv != nil {
+ _, ok := cv.peers[peer.PublicKey]
+ if ok {
+ someMatch = true
+ break
+ }
+ }
+ for _, peer := range config.Peers {
+ if pv := cv.peers[peer.PublicKey]; (!someMatch && len(all) > 0) || pv != nil {
+ if pv == nil {
+ pv = all[0]
+ all = all[1:]
+ k, e := conf.NewPrivateKeyFromString(pv.publicKey.text.Text())
+ if e != nil {
+ continue
+ }
+ delete(cv.peers, *k)
+ cv.peers[peer.PublicKey] = pv
+ }
pv.apply(&peer)
inverse[pv] = false
} else {