Skip to content

Commit

Permalink
Refactor: preallocate slices (golangci#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored and SeigeC committed Apr 4, 2023
1 parent ec17bff commit 99745ce
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/printers/codeclimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/result/processors/nolint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/timeutils/stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
}
Expand Down

0 comments on commit 99745ce

Please sign in to comment.