mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-15 19:41:02 +00:00
performance: do Metrics merge with less copying
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user