From 0f9e14dfd26eca67eb591d38ca02519cccc2ab6d Mon Sep 17 00:00:00 2001 From: Joe Andaverde Date: Sun, 14 May 2023 09:21:36 -0500 Subject: [PATCH] Add length hints for resources Signed-off-by: Joe Andaverde --- pkg/cache/v3/resources.go | 6 +++--- pkg/cache/v3/snapshot.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cache/v3/resources.go b/pkg/cache/v3/resources.go index 92df743f66..60f0ea09f4 100644 --- a/pkg/cache/v3/resources.go +++ b/pkg/cache/v3/resources.go @@ -13,7 +13,7 @@ type Resources struct { // IndexResourcesByName creates a map from the resource name to the resource. func IndexResourcesByName(items []types.ResourceWithTTL) map[string]types.ResourceWithTTL { - indexed := make(map[string]types.ResourceWithTTL) + indexed := make(map[string]types.ResourceWithTTL, len(items)) for _, item := range items { indexed[GetResourceName(item.Resource)] = item } @@ -22,7 +22,7 @@ func IndexResourcesByName(items []types.ResourceWithTTL) map[string]types.Resour // IndexRawResourcesByName creates a map from the resource name to the resource. func IndexRawResourcesByName(items []types.Resource) map[string]types.Resource { - indexed := make(map[string]types.Resource) + indexed := make(map[string]types.Resource, len(items)) for _, item := range items { indexed[GetResourceName(item)] = item } @@ -31,7 +31,7 @@ func IndexRawResourcesByName(items []types.Resource) map[string]types.Resource { // NewResources creates a new resource group. func NewResources(version string, items []types.Resource) Resources { - itemsWithTTL := []types.ResourceWithTTL{} + itemsWithTTL := make([]types.ResourceWithTTL, 0, len(items)) for _, item := range items { itemsWithTTL = append(itemsWithTTL, types.ResourceWithTTL{Resource: item}) } diff --git a/pkg/cache/v3/snapshot.go b/pkg/cache/v3/snapshot.go index 2cbcaf39e4..ca7c9b5af8 100644 --- a/pkg/cache/v3/snapshot.go +++ b/pkg/cache/v3/snapshot.go @@ -185,7 +185,7 @@ func (s *Snapshot) ConstructVersionMap() error { return err } if _, ok := s.VersionMap[typeURL]; !ok { - s.VersionMap[typeURL] = make(map[string]string) + s.VersionMap[typeURL] = make(map[string]string, len(resources.Items)) } for _, r := range resources.Items {