Merge pull request #3143 from weaveworks/unsafe-add-children

Use unsafe merge in joinResults.addChildAndChildren()
This commit is contained in:
Bryan Boreham
2018-04-15 21:46:23 +01:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -169,6 +169,7 @@ func (ret *joinResults) mapChild(from, to string) {
}
// Add m into the results as a top-level node, mapped from original ID
// Note it is not safe to mix calls to add() with addChild(), addChildAndChildren() or addUnmappedChild()
func (ret *joinResults) add(from string, m report.Node) {
if existing, ok := ret.nodes[m.ID]; ok {
m = m.Merge(existing)
@@ -203,7 +204,7 @@ func (ret *joinResults) addChild(m report.Node, id string, topology string) {
func (ret *joinResults) addChildAndChildren(m report.Node, id string, topology string) {
ret.addUnmappedChild(m, id, topology)
result := ret.nodes[id]
result.Children = result.Children.Merge(m.Children)
result.Children.UnsafeMerge(m.Children)
ret.nodes[id] = result
ret.mapChild(m.ID, id)
}

View File

@@ -72,6 +72,13 @@ func (n NodeSet) Delete(ids ...string) NodeSet {
return NodeSet{result}
}
// UnsafeMerge combines the two NodeSets, altering n
func (n *NodeSet) UnsafeMerge(other NodeSet) {
other.psMap.ForEach(func(key string, otherVal interface{}) {
n.psMap = n.psMap.UnsafeMutableSet(key, otherVal)
})
}
// Merge combines the two NodeSets and returns a new result.
func (n NodeSet) Merge(other NodeSet) NodeSet {
nSize, otherSize := n.Size(), other.Size()