diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-08 22:06:13 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-08 22:06:13 +0200 |
commit | a4be0f1d662bfa6c29a948b85db7155e0b115840 (patch) | |
tree | fcc9af5807f4d483725bf38cd7c50afbcae604bc /ui | |
parent | ui: fix ctrl+a on list invalidating list (diff) | |
download | wireguard-windows-a4be0f1d662bfa6c29a948b85db7155e0b115840.tar.xz wireguard-windows-a4be0f1d662bfa6c29a948b85db7155e0b115840.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.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/confview.go | 22 |
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 { |