diff --git a/render/render.go b/render/render.go index 1ba43f48c..eb3b6c8a2 100644 --- a/render/render.go +++ b/render/render.go @@ -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) } diff --git a/report/node_set.go b/report/node_set.go index eef713748..e236bd3db 100644 --- a/report/node_set.go +++ b/report/node_set.go @@ -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()