refactor: optimise "empty" case in report set constructors

This commit is contained in:
Matthias Radestock
2017-07-03 01:26:22 +01:00
parent 9dc50b5202
commit b5f3aa68ae
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -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...))
}
+3
View File
@@ -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()