mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 03:46:45 +00:00
refactor: optimise "empty" case in report set constructors
This commit is contained in:
@@ -7,11 +7,17 @@ var emptyIDList = IDList(MakeStringSet())
|
||||
|
||||
// MakeIDList makes a new IDList.
|
||||
func MakeIDList(ids ...string) IDList {
|
||||
if len(ids) == 0 {
|
||||
return emptyIDList
|
||||
}
|
||||
return IDList(MakeStringSet(ids...))
|
||||
}
|
||||
|
||||
// Add is the only correct way to add ids to an IDList.
|
||||
func (a IDList) Add(ids ...string) IDList {
|
||||
if len(ids) == 0 {
|
||||
return a
|
||||
}
|
||||
return IDList(StringSet(a).Add(ids...))
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ func MakeNodeSet(nodes ...Node) NodeSet {
|
||||
// Add adds the nodes to the NodeSet. Add is the only valid way to grow a
|
||||
// NodeSet. Add returns the NodeSet to enable chaining.
|
||||
func (n NodeSet) Add(nodes ...Node) NodeSet {
|
||||
if len(nodes) == 0 {
|
||||
return n
|
||||
}
|
||||
result := n.psMap
|
||||
if result == nil {
|
||||
result = ps.NewMap()
|
||||
|
||||
Reference in New Issue
Block a user