Use unsafe merge in joinResults.addChildAndChildren(), for performance

This commit is contained in:
Bryan Boreham
2018-04-15 09:39:21 +00:00
parent b8dae7768d
commit 3711876194
2 changed files with 8 additions and 1 deletions

View File

@@ -203,7 +203,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()