From b5f3aa68ae0a08a655c397f575892a921e1f127e Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 3 Jul 2017 00:32:35 +0100 Subject: [PATCH] refactor: optimise "empty" case in report set constructors --- report/id_list.go | 6 ++++++ report/node_set.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/report/id_list.go b/report/id_list.go index b285d5dbf..d75df56c3 100644 --- a/report/id_list.go +++ b/report/id_list.go @@ -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...)) } diff --git a/report/node_set.go b/report/node_set.go index 1baf2152c..3c4ba7141 100644 --- a/report/node_set.go +++ b/report/node_set.go @@ -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()