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

fix: slice init length #35848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ntheanh201
Copy link

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

Copy link

linux-foundation-easycla bot commented Oct 17, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@atoulme atoulme added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Oct 17, 2024
Copy link
Contributor

@atoulme atoulme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@songy23 songy23 left a 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))
Copy link
Member

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.

Copy link
Author

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

Copy link
Author

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 ?

Copy link
Contributor

github-actions bot commented Nov 7, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal/filter receiver/k8sobjects Skip Changelog PRs that do not require a CHANGELOG.md entry Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants