Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unnecessary and dead Copy() #2675

Merged
merged 2 commits into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions extras/generate_latest_map
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ function generate_latest_map() {
return ${empty_latest_map_variable}
}

// Copy is a noop, as ${latest_map_type}s are immutable.
func (m ${latest_map_type}) Copy() ${latest_map_type} {
return m
}

// Size returns the number of elements.
func (m ${latest_map_type}) Size() int {
if m.Map == nil {
Expand Down
26 changes: 0 additions & 26 deletions render/detailed/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,3 @@ func TestNodeMetadata(t *testing.T) {
}
}
}

func TestMetadataRowCopy(t *testing.T) {
var (
row = report.MetadataRow{
ID: "id",
Value: "value",
Priority: 1,
Datatype: "datatype",
}
cp = row.Copy()
)

// copy should be identical
if !reflect.DeepEqual(row, cp) {
t.Error(test.Diff(row, cp))
}

// changing the copy should not change the original
cp.ID = ""
cp.Value = ""
cp.Priority = 2
cp.Datatype = ""
if row.ID != "id" || row.Value != "value" || row.Priority != 1 || row.Datatype != "datatype" {
t.Errorf("Expected changing the copy not to modify the original")
}
}
5 changes: 0 additions & 5 deletions report/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func MakeNodeControls() NodeControls {
return emptyNodeControls
}

// Copy is a noop, as NodeControls is immutable
func (nc NodeControls) Copy() NodeControls {
return nc
}

// Merge returns the newest of the two NodeControls; it does not take the union
// of the valid Controls.
func (nc NodeControls) Merge(other NodeControls) NodeControls {
Expand Down
5 changes: 0 additions & 5 deletions report/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ func MakeCounters() Counters {
return emptyCounters
}

// Copy is a noop
func (c Counters) Copy() Counters {
return c
}

// Add value to the counter 'key'
func (c Counters) Add(key string, value int) Counters {
if c.psMap == nil {
Expand Down
5 changes: 0 additions & 5 deletions report/edge_metadatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func MakeEdgeMetadatas() EdgeMetadatas {
return emptyEdgeMetadatas
}

// Copy is a noop
func (c EdgeMetadatas) Copy() EdgeMetadatas {
return c
}

// Add value to the counter 'key'
func (c EdgeMetadatas) Add(key string, value EdgeMetadata) EdgeMetadatas {
if c.psMap == nil {
Expand Down
5 changes: 0 additions & 5 deletions report/id_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ func (a IDList) Add(ids ...string) IDList {
return IDList(StringSet(a).Add(ids...))
}

// Copy returns a copy of the IDList.
func (a IDList) Copy() IDList {
return IDList(StringSet(a).Copy())
}

// Merge all elements from a and b into a new list
func (a IDList) Merge(b IDList) IDList {
return IDList(StringSet(a).Merge(StringSet(b)))
Expand Down
10 changes: 0 additions & 10 deletions report/latest_map_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ func MakeStringLatestMap() StringLatestMap {
return emptyStringLatestMap
}

// Copy is a noop, as StringLatestMaps are immutable.
func (m StringLatestMap) Copy() StringLatestMap {
return m
}

// Size returns the number of elements.
func (m StringLatestMap) Size() int {
if m.Map == nil {
Expand Down Expand Up @@ -168,11 +163,6 @@ func MakeNodeControlDataLatestMap() NodeControlDataLatestMap {
return emptyNodeControlDataLatestMap
}

// Copy is a noop, as NodeControlDataLatestMaps are immutable.
func (m NodeControlDataLatestMap) Copy() NodeControlDataLatestMap {
return m
}

// Size returns the number of elements.
func (m NodeControlDataLatestMap) Size() int {
if m.Map == nil {
Expand Down
12 changes: 1 addition & 11 deletions report/metadata_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ type MetadataTemplate struct {
From string `json:"from,omitempty"` // Defines how to get the value from a report node
}

// Copy returns a value-copy of the template
func (t MetadataTemplate) Copy() MetadataTemplate {
return t
}

// MetadataRows returns the rows for a node
func (t MetadataTemplate) MetadataRows(n Node) []MetadataRow {
from := fromDefault
Expand Down Expand Up @@ -90,11 +85,6 @@ type MetadataRow struct {
Truncate int `json:"truncate,omitempty"`
}

// Copy returns a value copy of a metadata row.
func (m MetadataRow) Copy() MetadataRow {
return m
}

// MetadataTemplates is a mergeable set of metadata templates
type MetadataTemplates map[string]MetadataTemplate

Expand All @@ -115,7 +105,7 @@ func (e MetadataTemplates) Copy() MetadataTemplates {
}
result := MetadataTemplates{}
for k, v := range e {
result[k] = v.Copy()
result[k] = v
}
return result
}
Expand Down
7 changes: 1 addition & 6 deletions report/metric_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ func (t MetricTemplate) MetricRows(n Node) []MetricRow {
return []MetricRow{row}
}

// Copy returns a value-copy of the metric template
func (t MetricTemplate) Copy() MetricTemplate {
return t
}

// MetricTemplates is a mergeable set of metric templates
type MetricTemplates map[string]MetricTemplate

Expand All @@ -59,7 +54,7 @@ func (e MetricTemplates) Copy() MetricTemplates {
}
result := MetricTemplates{}
for k, v := range e {
result[k] = v.Copy()
result[k] = v
}
return result
}
Expand Down
5 changes: 0 additions & 5 deletions report/node_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func (n NodeSet) ForEach(f func(Node)) {
}
}

// Copy is a noop
func (n NodeSet) Copy() NodeSet {
return n
}

func (n NodeSet) String() string {
buf := bytes.NewBufferString("{")
for _, key := range mapKeys(n.psMap) {
Expand Down
5 changes: 0 additions & 5 deletions report/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ func (s Sets) Merge(other Sets) Sets {
return Sets{result}
}

// Copy is a noop
func (s Sets) Copy() Sets {
return s
}

func (s Sets) String() string {
return mapToString(s.psMap)
}
Expand Down
10 changes: 0 additions & 10 deletions report/string_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,3 @@ func (s StringSet) Merge(other StringSet) StringSet {
}
}
}

// Copy returns a value copy of the StringSet.
func (s StringSet) Copy() StringSet {
if s == nil {
return s
}
result := make(StringSet, len(s))
copy(result, s)
return result
}
28 changes: 0 additions & 28 deletions report/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,6 @@ func (t rowsByID) Len() int { return len(t) }
func (t rowsByID) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t rowsByID) Less(i, j int) bool { return t[i].ID < t[j].ID }

// Copy returns a copy of the Row.
func (r Row) Copy() Row {
entriesCopy := make(map[string]string, len(r.Entries))
for key, value := range r.Entries {
entriesCopy[key] = value
}
r.Entries = entriesCopy
return r
}

// Table is the type for a table in the UI.
type Table struct {
ID string `json:"id"`
Expand All @@ -201,24 +191,6 @@ func (t tablesByID) Len() int { return len(t) }
func (t tablesByID) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t tablesByID) Less(i, j int) bool { return t[i].ID < t[j].ID }

// Copy returns a copy of the Table.
func (t Table) Copy() Table {
result := Table{
ID: t.ID,
Label: t.Label,
Type: t.Type,
Columns: make([]Column, 0, len(t.Columns)),
Rows: make([]Row, 0, len(t.Rows)),
}
for _, column := range t.Columns {
result.Columns = append(result.Columns, column)
}
for _, row := range t.Rows {
result.Rows = append(result.Rows, row)
}
return result
}

// TableTemplate describes how to render a table for the UI.
type TableTemplate struct {
ID string `json:"id"`
Expand Down
2 changes: 1 addition & 1 deletion test/utils/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func PruneNode(node report.Node) report.Node {
return report.MakeNode(
node.ID).
WithTopology(node.Topology).
WithAdjacent(node.Adjacency.Copy()...).
WithAdjacent(node.Adjacency...).
WithChildren(prunedChildren)
}