Preallocate slices of known length

This commit is contained in:
Holger Obermaier
2026-02-12 15:07:39 +01:00
parent 555ba9504a
commit d715f7aa07
2 changed files with 4 additions and 4 deletions

View File

@@ -49,7 +49,7 @@ jobs:
# Running the linter requires likwid.h, which gets downloaded in the build step # Running the linter requires likwid.h, which gets downloaded in the build step
- name: Static Analysis with GolangCI-Lint and Upload Report with reviewdog - name: Static Analysis with GolangCI-Lint and Upload Report with reviewdog
run: | run: |
golangci-lint run --enable errorlint,govet,misspell,modernize,staticcheck,unconvert,wastedassign | reviewdog -f=golangci-lint -name "Check golangci-lint on build-latest" -reporter=github-check -filter-mode=nofilter -fail-level none golangci-lint run --enable errorlint,govet,misspell,modernize,prealloc,staticcheck,unconvert,wastedassign | reviewdog -f=golangci-lint -name "Check golangci-lint on build-latest" -reporter=github-check -filter-mode=nofilter -fail-level none
env: env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -126,13 +126,13 @@ func checkMetricType(t string) bool {
} }
func genLikwidEventSet(input LikwidCollectorEventsetConfig) LikwidEventsetConfig { func genLikwidEventSet(input LikwidCollectorEventsetConfig) LikwidEventsetConfig {
clist := make([]string, len(input.Events)) clist := make([]string, 0, len(input.Events))
for k := range input.Events { for k := range input.Events {
clist = append(clist, k) clist = append(clist, k)
} }
slices.Sort(clist) slices.Sort(clist)
tmplist := make([]string, len(clist)) tmplist := make([]string, 0, len(clist))
elist := make([]*C.char, len(clist)) elist := make([]*C.char, 0, len(clist))
for _, k := range clist { for _, k := range clist {
v := input.Events[k] v := input.Events[k]
tmplist = append(tmplist, fmt.Sprintf("%s:%s", v, k)) tmplist = append(tmplist, fmt.Sprintf("%s:%s", v, k))