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

*: Enable the prealloc linter #10762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timflannagan
Copy link
Member

Description

Enables the https://golangci-lint.run/usage/linters/#prealloc linter. We're relying on the
simple: true default setting here. Any additional settings could overkill.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Signed-off-by: timflannagan <[email protected]>
@timflannagan
Copy link
Member Author

Related to #10496

@@ -261,7 +261,7 @@ func convertHeaderModifier(kctx krt.HandlerContext, f *gwv1.HTTPHeaderFilter) fu
if f == nil {
return nil
}
var headersToAddd []*envoy_config_core_v3.HeaderValueOption
headersToAddd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
headersToAddd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))
headersToAdd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))

@@ -294,7 +294,7 @@ func convertResponseHeaderModifier(kctx krt.HandlerContext, f *gwv1.HTTPHeaderFi
if f == nil {
return nil
}
var headersToAddd []*envoy_config_core_v3.HeaderValueOption
headersToAddd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
headersToAddd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))
headersToAdd := make([]*envoy_config_core_v3.HeaderValueOption, 0, len(f.Add)+len(f.Set))

Comment on lines +95 to +96
certs := make([][]byte, 0, len(s.secrets))
items := make([]cache_types.Resource, 0, len(s.secrets))
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, the cap should be higher, looks like you can append to certs up to 4 times within each iteration, and append to items twice each iteration

@@ -51,7 +51,7 @@ func resourcesFromSnapshot(snap envoycache.ResourceSnapshot) (*EnvoyResources, e
// listenersFromSnapshot accepts a Snapshot and extracts from it a slice of pointers to
// the Listener structs contained in the Snapshot.
func listenersFromSnapshot(snap envoycache.ResourceSnapshot) ([]*envoy_config_listener_v3.Listener, error) {
var listeners []*envoy_config_listener_v3.Listener
listeners := make([]*envoy_config_listener_v3.Listener, 0, len(snap.GetResources(envoyresource.ListenerType)))
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't know how expensive the snap.GetResources call is, but should we just call it once and set it as a variable? (same with the other instances below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants