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

dataclients/kubernetes: preallocate slices #2786

Merged
merged 1 commit into from
Dec 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dataclients/kubernetes/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ func formatEndpoint(a *address, p *port, protocol string) string {
}

func formatEndpointsForSubsetAddresses(addresses []*address, port *port, protocol string) []string {
var result []string
result := make([]string, 0, len(addresses))
for _, address := range addresses {
result = append(result, formatEndpoint(address, port, protocol))
}

return result

}

func (ep *endpoint) targetsByServicePort(protocol string, servicePort *servicePort) []string {
Expand Down
6 changes: 2 additions & 4 deletions dataclients/kubernetes/endpointslices.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ func (eps *skipperEndpointSlice) targetsByServicePort(protocol, scheme string, s
port = eps.getPort(protocol, servicePort.Name, servicePort.Port)
}

var result []string
result := make([]string, 0, len(eps.Endpoints))
for _, ep := range eps.Endpoints {
result = append(result, formatEndpointString(ep.Address, scheme, port))
}

return result
}

Expand All @@ -68,11 +67,10 @@ func (eps *skipperEndpointSlice) targetsByServiceTarget(protocol, scheme string,
pValue, _ := serviceTarget.Value.(int)
port := eps.getPort(protocol, pName, pValue)

var result []string
result := make([]string, 0, len(eps.Endpoints))
for _, ep := range eps.Endpoints {
result = append(result, formatEndpointString(ep.Address, scheme, port))
}

return result
}

Expand Down
2 changes: 1 addition & 1 deletion dataclients/kubernetes/kubernetestest/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func safeFileClose(t *testing.T, fd *os.File) {
}

func compileRegexps(s []string) ([]*regexp.Regexp, error) {
var r []*regexp.Regexp
r := make([]*regexp.Regexp, 0, len(s))
for _, si := range s {
ri, err := regexp.Compile(si)
if err != nil {
Expand Down