From a4be0f1d662bfa6c29a948b85db7155e0b115840 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 8 May 2019 22:06:13 +0200 Subject: 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. --- ui/confview.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'ui/confview.go') 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 { -- cgit v1.2.3-59-g8ed1b