Merge pull request #2548 from weaveworks/nodeset-unsorted-foreach

optimise: don't sort in NodeSet.ForEach
This commit is contained in:
Matthias Radestock
2017-05-30 14:54:13 +01:00
committed by GitHub
2 changed files with 6 additions and 5 deletions

View File

@@ -92,13 +92,12 @@ func (n NodeSet) Size() int {
return n.psMap.Size()
}
// ForEach executes f for each node in the set. Nodes are traversed in sorted
// order.
// ForEach executes f for each node in the set.
func (n NodeSet) ForEach(f func(Node)) {
for _, key := range mapKeys(n.psMap) {
if val, ok := n.psMap.Lookup(key); ok {
if n.psMap != nil {
n.psMap.ForEach(func(_ string, val interface{}) {
f(val.(Node))
}
})
}
}

View File

@@ -2,6 +2,7 @@ package report_test
import (
"fmt"
"sort"
"testing"
"github.com/weaveworks/scope/report"
@@ -40,6 +41,7 @@ func TestMakeNodeSet(t *testing.T) {
set := report.MakeNodeSet(inputs...)
var have []string
set.ForEach(func(node report.Node) { have = append(have, node.ID) })
sort.Strings(have)
if !reflect.DeepEqual(testcase.wants, have) {
t.Errorf("%#v: want %#v, have %#v", testcase.inputs, testcase.wants, have)
}