Skip to content

Commit

Permalink
lxc/completion: Pre-allocate slices where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Dec 18, 2024
1 parent 586d229 commit ff7ea8c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (g *cmdGlobal) cmpClusterGroupNames(toComplete string) ([]string, cobra.She
// cmpClusterGroups provides shell completion for cluster groups and their remotes.
// It takes a partial input string and returns a list of matching cluster groups along with a shell completion directive.
func (g *cmdGlobal) cmpClusterGroups(toComplete string) ([]string, cobra.ShellCompDirective) {
var results []string
cmpDirectives := cobra.ShellCompDirectiveNoFileComp

resources, _ := g.ParseServers(toComplete)
Expand All @@ -62,6 +61,8 @@ func (g *cmdGlobal) cmpClusterGroups(toComplete string) ([]string, cobra.ShellCo
return nil, cobra.ShellCompDirectiveError
}

results := make([]string, 0, len(groups))

for _, group := range groups {
var name string

Expand Down Expand Up @@ -105,7 +106,7 @@ func (g *cmdGlobal) cmpClusterMemberConfigs(memberName string) ([]string, cobra.
return nil, cobra.ShellCompDirectiveError
}

var results []string
results := make([]string, 0, len(member.Config))
for k := range member.Config {
results = append(results, k)
}
Expand Down Expand Up @@ -510,7 +511,7 @@ func (g *cmdGlobal) cmpInstanceDeviceNames(instanceName string) ([]string, cobra
return nil, cobra.ShellCompDirectiveError
}

var results []string
results := make([]string, 0, len(instanceNameOnly.Devices))
for k := range instanceNameOnly.Devices {
results = append(results, k)
}
Expand Down Expand Up @@ -754,7 +755,7 @@ func (g *cmdGlobal) cmpNetworkACLConfigs(aclName string) ([]string, cobra.ShellC
return nil, cobra.ShellCompDirectiveError
}

var results []string
results := make([]string, 0, len(acl.Config))
for k := range acl.Config {
results = append(results, k)
}
Expand All @@ -765,7 +766,6 @@ func (g *cmdGlobal) cmpNetworkACLConfigs(aclName string) ([]string, cobra.ShellC
// cmpNetworkACLs provides shell completion for network ACL's.
// It takes a partial input string and returns a list of matching network ACL's along with a shell completion directive.
func (g *cmdGlobal) cmpNetworkACLs(toComplete string) ([]string, cobra.ShellCompDirective) {
var results []string
cmpDirectives := cobra.ShellCompDirectiveNoFileComp

resources, _ := g.ParseServers(toComplete)
Expand All @@ -781,6 +781,7 @@ func (g *cmdGlobal) cmpNetworkACLs(toComplete string) ([]string, cobra.ShellComp
return nil, cobra.ShellCompDirectiveError
}

results := make([]string, 0, len(acls))
for _, acl := range acls {
var name string

Expand Down Expand Up @@ -832,7 +833,7 @@ func (g *cmdGlobal) cmpNetworkForwardConfigs(networkName string, listenAddress s
return nil, cobra.ShellCompDirectiveError
}

var results []string
results := make([]string, 0, len(forward.Config))
for k := range forward.Config {
results = append(results, k)
}
Expand Down Expand Up @@ -1182,7 +1183,7 @@ func (g *cmdGlobal) cmpProfileConfigs(profileName string) ([]string, cobra.Shell
return nil, cobra.ShellCompDirectiveError
}

var configs []string
configs := make([]string, 0, len(profile.Config))
for c := range profile.Config {
configs = append(configs, c)
}
Expand Down Expand Up @@ -1283,7 +1284,7 @@ func (g *cmdGlobal) cmpProjectConfigs(projectName string) ([]string, cobra.Shell
return nil, cobra.ShellCompDirectiveError
}

var configs []string
configs := make([]string, 0, len(project.Config))
for c := range project.Config {
configs = append(configs, c)
}
Expand Down

0 comments on commit ff7ea8c

Please sign in to comment.