Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add size hints for resource maps and slice #692

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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