Skip to content

Commit 8aa46c2

Browse files
committed
Init slice with provided capacity if it's known in advance
1 parent c60ccf9 commit 8aa46c2

File tree

9 files changed

+15
-13
lines changed

9 files changed

+15
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# VS Code
1010
.vscode
1111

12+
# IntelliJ
13+
.idea
14+
1215
# macOS
1316
.DS_Store
1417

api/queries_repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type RepoNetworkResult struct {
9797

9898
// RepoNetwork inspects the relationship between multiple GitHub repositories
9999
func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, error) {
100-
queries := []string{}
100+
queries := make([]string, 0, len(repos))
101101
for i, repo := range repos {
102102
queries = append(queries, fmt.Sprintf(`
103103
repo_%03d: repository(owner: %q, name: %q) {
@@ -150,7 +150,7 @@ func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, e
150150
return result, err
151151
}
152152

153-
keys := []string{}
153+
keys := make([]string, 0, len(graphqlResult))
154154
for key := range graphqlResult {
155155
keys = append(keys, key)
156156
}

command/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func labelList(issue api.Issue) string {
429429
return ""
430430
}
431431

432-
labelNames := []string{}
432+
labelNames := make([]string, 0, len(issue.Labels.Nodes))
433433
for _, label := range issue.Labels.Nodes {
434434
labelNames = append(labelNames, label.Name)
435435
}

command/pr_checkout.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
3838
headRemote, _ = remotes.FindByRepo(pr.HeadRepositoryOwner.Login, pr.HeadRepository.Name)
3939
}
4040

41-
cmdQueue := [][]string{}
42-
41+
cmdQueue := make([][]string, 0, 4)
4342
newBranchName := pr.HeadRefName
4443
if headRemote != nil {
4544
// there is an existing git remote for PR head

command/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var initContext = func() context.Context {
9797
// BasicClient returns an API client that borrows from but does not depend on
9898
// user configuration
9999
func BasicClient() (*api.Client, error) {
100-
opts := []api.ClientOption{}
100+
opts := make([]api.ClientOption, 0, 1)
101101
if verbose := os.Getenv("DEBUG"); verbose != "" {
102102
opts = append(opts, apiVerboseLog())
103103
}
@@ -122,7 +122,7 @@ var apiClientForContext = func(ctx context.Context) (*api.Client, error) {
122122
if err != nil {
123123
return nil, err
124124
}
125-
opts := []api.ClientOption{}
125+
opts := make([]api.ClientOption, 0, 4)
126126
if verbose := os.Getenv("DEBUG"); verbose != "" {
127127
opts = append(opts, apiVerboseLog())
128128
}

command/title_body_survey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func selectTemplate(templatePaths []string) (string, error) {
5454
Index int
5555
}{}
5656
if len(templatePaths) > 1 {
57-
templateNames := []string{}
57+
templateNames := make([]string, 0, len(templatePaths))
5858
for _, p := range templatePaths {
5959
templateNames = append(templateNames, githubtemplate.ExtractName(p))
6060
}
@@ -110,7 +110,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle string, providedBody stri
110110
},
111111
}
112112

113-
qs := []*survey.Question{}
113+
var qs = []*survey.Question{}
114114
if providedTitle == "" {
115115
qs = append(qs, titleQuestion)
116116
}

context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ResolveRemotesToRepos(remotes Remotes, client *api.Client, base string) (Re
3838
hasBaseOverride := base != ""
3939
baseOverride := ghrepo.FromFullName(base)
4040
foundBaseOverride := false
41-
repos := []ghrepo.Interface{}
41+
repos := make([]ghrepo.Interface, 0, lenRemotesForLookup)
4242
for _, r := range remotes[:lenRemotesForLookup] {
4343
repos = append(repos, r)
4444
if ghrepo.IsSame(r, baseOverride) {

git/ssh_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func ParseSSHConfig() SSHAliasMap {
5757
configFiles = append([]string{userConfig}, configFiles...)
5858
}
5959

60-
openFiles := []io.Reader{}
60+
openFiles := make([]io.Reader, 0, len(configFiles))
6161
for _, file := range configFiles {
6262
f, err := os.Open(file)
6363
if err != nil {

internal/cobrafish/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func flagRequiresArgumentCompletion(flag *pflag.Flag) string {
117117
}
118118

119119
func subCommandPath(rootCmd *cobra.Command, cmd *cobra.Command) string {
120-
path := []string{}
120+
path := make([]string, 0, 1)
121121
currentCmd := cmd
122122
if rootCmd == cmd {
123123
return ""
@@ -142,7 +142,7 @@ func rangeCommands(cmd *cobra.Command, callback func(subCmd *cobra.Command)) {
142142

143143
func commandCompletionCondition(rootCmd, cmd *cobra.Command) string {
144144
localNonPersistentFlags := cmd.LocalNonPersistentFlags()
145-
bareConditions := []string{}
145+
bareConditions := make([]string, 0, 1)
146146
if rootCmd != cmd {
147147
bareConditions = append(bareConditions, fmt.Sprintf("__fish_%s_seen_subcommand_path %s", rootCmd.Name(), subCommandPath(rootCmd, cmd)))
148148
} else {

0 commit comments

Comments
 (0)