Skip to content

Commit

Permalink
Add length hints for resources (#692)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Andaverde <joe@temporal.io>
  • Loading branch information
dynajoe committed May 15, 2023
1 parent 8f62900 commit f040a1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/cache/v3/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v3/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f040a1a

Please sign in to comment.