Refactor: preallocate slices (#2340)

This commit is contained in:
Oleksandr Redko 2021-11-02 18:27:06 +02:00 committed by GitHub
parent a8887d5655
commit 1be9570abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 6 deletions

View File

@ -80,7 +80,7 @@ func (e *Executor) executeLintersHelp(_ *cobra.Command, args []string) {
color.Green("\nLinters presets:")
for _, p := range e.DBManager.AllPresets() {
linters := e.DBManager.GetAllLinterConfigsForPreset(p)
linterNames := []string{}
linterNames := make([]string, 0, len(linters))
for _, lc := range linters {
linterNames = append(linterNames, lc.Name())
}

View File

@ -34,7 +34,7 @@ func NewWSL() *goanalysis.Linter {
).WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
var (
files = []string{}
files = make([]string, 0, len(pass.Files))
linterCfg = lintCtx.Cfg.LintersSettings.WSL
processorCfg = wsl.Configuration{
StrictAppend: linterCfg.StrictAppend,

View File

@ -31,7 +31,7 @@ func NewCodeClimate() *CodeClimate {
}
func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
codeClimateIssues := []CodeClimateIssue{}
codeClimateIssues := make([]CodeClimateIssue, 0, len(issues))
for i := range issues {
issue := &issues[i]
codeClimateIssue := CodeClimateIssue{}

View File

@ -284,7 +284,7 @@ func (p Nolint) Finish() {
return
}
unknownLinters := []string{}
unknownLinters := make([]string, 0, len(p.unknownLintersSet))
for name := range p.unknownLintersSet {
unknownLinters = append(unknownLinters, name)
}

View File

@ -36,7 +36,7 @@ type stageDuration struct {
}
func (s *Stopwatch) stageDurationsSorted() []stageDuration {
stageDurations := []stageDuration{}
stageDurations := make([]stageDuration, 0, len(s.stages))
for n, d := range s.stages {
stageDurations = append(stageDurations, stageDuration{
name: n,
@ -56,7 +56,7 @@ func (s *Stopwatch) sprintStages() string {
stageDurations := s.stageDurationsSorted()
stagesStrings := []string{}
stagesStrings := make([]string, 0, len(stageDurations))
for _, s := range stageDurations {
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))
}