diff --git a/report/metrics.go b/report/metrics.go index 2d0f7e529..44c5a906d 100644 --- a/report/metrics.go +++ b/report/metrics.go @@ -24,14 +24,25 @@ func (m Metrics) Merge(other Metrics) Metrics { return m } result := m.Copy() + result.UnsafeMerge(other) + return result +} + +// UnsafeMerge merges another set of Metrics into m, modifying the original. +func (m Metrics) UnsafeMerge(other Metrics) { + if len(m) == 0 { + if len(other) > 0 { + m = other.Copy() + } + return + } for k, v := range other { - if rv, ok := result[k]; ok { - result[k] = rv.Merge(v) + if rv, ok := m[k]; ok { + m[k] = rv.Merge(v) } else { - result[k] = v + m[k] = v } } - return result } // Copy returns a value copy of the sets map. diff --git a/report/node.go b/report/node.go index 9d075217b..045102779 100644 --- a/report/node.go +++ b/report/node.go @@ -186,7 +186,7 @@ func (n *Node) UnsafeMerge(other Node) { n.Sets = n.Sets.Merge(other.Sets) n.Adjacency = n.Adjacency.Merge(other.Adjacency) n.Latest = n.Latest.Merge(other.Latest) - n.Metrics = n.Metrics.Merge(other.Metrics) + n.Metrics.UnsafeMerge(other.Metrics) n.Parents = n.Parents.Merge(other.Parents) n.Children = n.Children.Merge(other.Children) }