Init slice with provided capacity if it's known in advance
This commit is contained in:
parent
c60ccf9a16
commit
8aa46c236e
9 changed files with 15 additions and 13 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -9,6 +9,9 @@
|
|||
# VS Code
|
||||
.vscode
|
||||
|
||||
# IntelliJ
|
||||
.idea
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ type RepoNetworkResult struct {
|
|||
|
||||
// RepoNetwork inspects the relationship between multiple GitHub repositories
|
||||
func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, error) {
|
||||
queries := []string{}
|
||||
queries := make([]string, 0, len(repos))
|
||||
for i, repo := range repos {
|
||||
queries = append(queries, fmt.Sprintf(`
|
||||
repo_%03d: repository(owner: %q, name: %q) {
|
||||
|
|
@ -150,7 +150,7 @@ func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, e
|
|||
return result, err
|
||||
}
|
||||
|
||||
keys := []string{}
|
||||
keys := make([]string, 0, len(graphqlResult))
|
||||
for key := range graphqlResult {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ func labelList(issue api.Issue) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
labelNames := []string{}
|
||||
labelNames := make([]string, 0, len(issue.Labels.Nodes))
|
||||
for _, label := range issue.Labels.Nodes {
|
||||
labelNames = append(labelNames, label.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
|
|||
headRemote, _ = remotes.FindByRepo(pr.HeadRepositoryOwner.Login, pr.HeadRepository.Name)
|
||||
}
|
||||
|
||||
cmdQueue := [][]string{}
|
||||
|
||||
cmdQueue := make([][]string, 0, 4)
|
||||
newBranchName := pr.HeadRefName
|
||||
if headRemote != nil {
|
||||
// there is an existing git remote for PR head
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ var initContext = func() context.Context {
|
|||
// BasicClient returns an API client that borrows from but does not depend on
|
||||
// user configuration
|
||||
func BasicClient() (*api.Client, error) {
|
||||
opts := []api.ClientOption{}
|
||||
opts := make([]api.ClientOption, 0, 1)
|
||||
if verbose := os.Getenv("DEBUG"); verbose != "" {
|
||||
opts = append(opts, apiVerboseLog())
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ var apiClientForContext = func(ctx context.Context) (*api.Client, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := []api.ClientOption{}
|
||||
opts := make([]api.ClientOption, 0, 4)
|
||||
if verbose := os.Getenv("DEBUG"); verbose != "" {
|
||||
opts = append(opts, apiVerboseLog())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func selectTemplate(templatePaths []string) (string, error) {
|
|||
Index int
|
||||
}{}
|
||||
if len(templatePaths) > 1 {
|
||||
templateNames := []string{}
|
||||
templateNames := make([]string, 0, len(templatePaths))
|
||||
for _, p := range templatePaths {
|
||||
templateNames = append(templateNames, githubtemplate.ExtractName(p))
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle string, providedBody stri
|
|||
},
|
||||
}
|
||||
|
||||
qs := []*survey.Question{}
|
||||
var qs = []*survey.Question{}
|
||||
if providedTitle == "" {
|
||||
qs = append(qs, titleQuestion)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func ResolveRemotesToRepos(remotes Remotes, client *api.Client, base string) (Re
|
|||
hasBaseOverride := base != ""
|
||||
baseOverride := ghrepo.FromFullName(base)
|
||||
foundBaseOverride := false
|
||||
repos := []ghrepo.Interface{}
|
||||
repos := make([]ghrepo.Interface, 0, lenRemotesForLookup)
|
||||
for _, r := range remotes[:lenRemotesForLookup] {
|
||||
repos = append(repos, r)
|
||||
if ghrepo.IsSame(r, baseOverride) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func ParseSSHConfig() SSHAliasMap {
|
|||
configFiles = append([]string{userConfig}, configFiles...)
|
||||
}
|
||||
|
||||
openFiles := []io.Reader{}
|
||||
openFiles := make([]io.Reader, 0, len(configFiles))
|
||||
for _, file := range configFiles {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ func flagRequiresArgumentCompletion(flag *pflag.Flag) string {
|
|||
}
|
||||
|
||||
func subCommandPath(rootCmd *cobra.Command, cmd *cobra.Command) string {
|
||||
path := []string{}
|
||||
path := make([]string, 0, 1)
|
||||
currentCmd := cmd
|
||||
if rootCmd == cmd {
|
||||
return ""
|
||||
|
|
@ -142,7 +142,7 @@ func rangeCommands(cmd *cobra.Command, callback func(subCmd *cobra.Command)) {
|
|||
|
||||
func commandCompletionCondition(rootCmd, cmd *cobra.Command) string {
|
||||
localNonPersistentFlags := cmd.LocalNonPersistentFlags()
|
||||
bareConditions := []string{}
|
||||
bareConditions := make([]string, 0, 1)
|
||||
if rootCmd != cmd {
|
||||
bareConditions = append(bareConditions, fmt.Sprintf("__fish_%s_seen_subcommand_path %s", rootCmd.Name(), subCommandPath(rootCmd, cmd)))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue