-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix: slice init length #35848
base: main
Are you sure you want to change the base?
fix: slice init length #35848
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -65,7 +65,7 @@ func (c *Config) Validate() error { | |||
for _, object := range c.Objects { | |||
gvrs, ok := validObjects[object.Name] | |||
if !ok { | |||
availableResource := make([]string, len(validObjects)) | |||
availableResource := make([]string, 0, len(validObjects)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use case would be better improved if we set via an index instead of append.
Leaving availableResource := make([]string, len(validObjects))
but doing availableResource[i] = k
feels the most efficient, since we know that every element in validObjects
needs to end up in availableResource
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we know the validObjects is a map, so if we wanna set the value to the index of availableResource, we need a counter there, IMO append is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to update availableResource @TylerHelmuth ?
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Description
The intention here is to correct the slice initialization by setting the capacity equal to the intended length and leaving the length as 0 for dynamic appending. This avoids over-allocating or pre-allocating empty values unnecessarily.
Link to tracking issue
Fixes
Testing
Documentation