Skip to content

Commit

Permalink
Optimize allocations a bit
Browse files Browse the repository at this point in the history
No need to allocate an empty slice, nil is fine in this case. Map of empty structs is good enough and uses a bit less memory.
  • Loading branch information
ash2k committed Oct 7, 2021
1 parent a33618c commit 7ee6ca6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/kstatus/polling/clusterreader/caching_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,19 @@ func buildGvkNamespaceSet(gks []schema.GroupKind, namespace string, gvkNamespace

type gvkNamespaceSet struct {
gvkNamespaces []gkNamespace
seen map[gkNamespace]bool
seen map[gkNamespace]struct{}
}

func newGnSet() *gvkNamespaceSet {
return &gvkNamespaceSet{
gvkNamespaces: make([]gkNamespace, 0),
seen: make(map[gkNamespace]bool),
seen: make(map[gkNamespace]struct{}),
}
}

func (g *gvkNamespaceSet) add(gn gkNamespace) {
if _, found := g.seen[gn]; !found {
g.gvkNamespaces = append(g.gvkNamespaces, gn)
g.seen[gn] = true
g.seen[gn] = struct{}{}
}
}

Expand Down

0 comments on commit 7ee6ca6

Please sign in to comment.