mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 21:09:38 +00:00
Merge pull request #2548 from weaveworks/nodeset-unsorted-foreach
optimise: don't sort in NodeSet.ForEach
This commit is contained in:
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user