From 2546930a1af1ca8f6ddbee166c87ecaaac818059 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Mon, 28 Jul 2014 00:08:15 +0100 Subject: [PATCH] Fix in-place removal --- config/config.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index f061ff8fc..44bb45282 100644 --- a/config/config.go +++ b/config/config.go @@ -403,16 +403,18 @@ func ensureNodePresent(nodes []NodeConfiguration, myID protocol.NodeID) []NodeCo } func ensureExistingNodes(nodes []NodeConfiguration, existingNodes map[protocol.NodeID]bool) []NodeConfiguration { + count := len(nodes) i := 0 - for _, node := range nodes { - if _, ok := existingNodes[node.NodeID]; !ok { - last := len(nodes) - 1 - nodes[i] = nodes[last] - nodes = nodes[:last] - } else { - i++ +loop: + for i < count { + if _, ok := existingNodes[nodes[i].NodeID]; !ok { + nodes[i] = nodes[count-1] + count-- + continue loop } + i++ } + nodes = nodes[0:count] sort.Sort(NodeConfigurationList(nodes))