Merge pull request #2675 from weaveworks/less-copy

refactor: remove unnecessary and dead Copy()
This commit is contained in:
Matthias Radestock
2017-07-05 14:33:31 +01:00
committed by GitHub
14 changed files with 3 additions and 127 deletions
-5
View File
@@ -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 {
-26
View File
@@ -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
View File
@@ -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 {
-5
View File
@@ -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 {
-5
View File
@@ -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 {
-5
View File
@@ -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)))
-10
View File
@@ -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 {
@@ -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 {
+1 -11
View File
@@ -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
@@ -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
@@ -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
}
+1 -6
View File
@@ -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
@@ -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
}
-5
View File
@@ -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) {
-5
View File
@@ -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)
}
-10
View File
@@ -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
View File
@@ -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"`
@@ -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"`
+1 -1
View File
@@ -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)
}