Skip to content

Commit 1be9570

Browse files
authored
Refactor: preallocate slices (#2340)
1 parent a8887d5 commit 1be9570

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

pkg/commands/help.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (e *Executor) executeLintersHelp(_ *cobra.Command, args []string) {
8080
color.Green("\nLinters presets:")
8181
for _, p := range e.DBManager.AllPresets() {
8282
linters := e.DBManager.GetAllLinterConfigsForPreset(p)
83-
linterNames := []string{}
83+
linterNames := make([]string, 0, len(linters))
8484
for _, lc := range linters {
8585
linterNames = append(linterNames, lc.Name())
8686
}

pkg/golinters/wsl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewWSL() *goanalysis.Linter {
3434
).WithContextSetter(func(lintCtx *linter.Context) {
3535
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
3636
var (
37-
files = []string{}
37+
files = make([]string, 0, len(pass.Files))
3838
linterCfg = lintCtx.Cfg.LintersSettings.WSL
3939
processorCfg = wsl.Configuration{
4040
StrictAppend: linterCfg.StrictAppend,

pkg/printers/codeclimate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewCodeClimate() *CodeClimate {
3131
}
3232

3333
func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
34-
codeClimateIssues := []CodeClimateIssue{}
34+
codeClimateIssues := make([]CodeClimateIssue, 0, len(issues))
3535
for i := range issues {
3636
issue := &issues[i]
3737
codeClimateIssue := CodeClimateIssue{}

pkg/result/processors/nolint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (p Nolint) Finish() {
284284
return
285285
}
286286

287-
unknownLinters := []string{}
287+
unknownLinters := make([]string, 0, len(p.unknownLintersSet))
288288
for name := range p.unknownLintersSet {
289289
unknownLinters = append(unknownLinters, name)
290290
}

pkg/timeutils/stopwatch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type stageDuration struct {
3636
}
3737

3838
func (s *Stopwatch) stageDurationsSorted() []stageDuration {
39-
stageDurations := []stageDuration{}
39+
stageDurations := make([]stageDuration, 0, len(s.stages))
4040
for n, d := range s.stages {
4141
stageDurations = append(stageDurations, stageDuration{
4242
name: n,
@@ -56,7 +56,7 @@ func (s *Stopwatch) sprintStages() string {
5656

5757
stageDurations := s.stageDurationsSorted()
5858

59-
stagesStrings := []string{}
59+
stagesStrings := make([]string, 0, len(stageDurations))
6060
for _, s := range stageDurations {
6161
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))
6262
}

0 commit comments

Comments
 (0)