Skip to content

Commit

Permalink
Remove copying Merge() on Report
Browse files Browse the repository at this point in the history
It was only used in a few places, and all of those were better off
using the Unsafe variant.
  • Loading branch information
bboreham committed Mar 6, 2020
1 parent b07bfb2 commit a47cf0a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestCollector(t *testing.T) {

c.Add(ctx, r2, nil)
merged := report.MakeReport()
merged = merged.Merge(r1)
merged = merged.Merge(r2)
merged.UnsafeMerge(r1)
merged.UnsafeMerge(r2)
have, err = c.Report(ctx, mtime.Now())
if err != nil {
t.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion probe/plugins/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *Registry) Report() (report.Report, error) {
if plugin.Implements("controller") {
r.updateAndRegisterControlsInReport(&pluginReport)
}
rpt = rpt.Merge(pluginReport)
rpt.UnsafeMerge(pluginReport)
})
return rpt, nil
}
Expand Down
4 changes: 2 additions & 2 deletions render/theinternet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestReportLocalNetworks(t *testing.T) {
r := report.MakeReport().Merge(report.Report{
r := report.Report{
Host: report.Topology{
Nodes: report.Nodes{
"nonets": report.MakeNode("nonets"),
Expand All @@ -27,7 +27,7 @@ func TestReportLocalNetworks(t *testing.T) {
),
},
},
})
}.Copy()
want := report.MakeNetworks()
for _, cidr := range []string{"10.0.0.1/8", "192.168.1.1/24", "10.32.0.1/12"} {
if err := want.AddCIDR(cidr); err != nil {
Expand Down
8 changes: 0 additions & 8 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,6 @@ func (r Report) Copy() Report {
return newReport
}

// Merge merges another Report into the receiver and returns the result. The
// original is not modified.
func (r Report) Merge(other Report) Report {
newReport := r.Copy()
newReport.UnsafeMerge(other)
return newReport
}

// UnsafeMerge merges another Report into the receiver. The original is modified.
func (r *Report) UnsafeMerge(other Report) {
r.DNS = r.DNS.Merge(other.DNS)
Expand Down

0 comments on commit a47cf0a

Please sign in to comment.