Skip to content

Commit

Permalink
dataclients/kubernetes: preallocate slices
Browse files Browse the repository at this point in the history
Preallocate some obvious cases found by https://github.com/alexkohler/prealloc

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov committed Dec 9, 2023
1 parent 7c60b1d commit 60ae90c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
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

0 comments on commit 60ae90c

Please sign in to comment.