Skip to content

Commit 7e6c2c6

Browse files
committed
refactor: map to slice
1 parent 4390f8a commit 7e6c2c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/cache/cache.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"errors"
88
"fmt"
99
"runtime"
10-
"sort"
10+
"slices"
11+
"strings"
1112
"sync"
1213

14+
"golang.org/x/exp/maps"
1315
"golang.org/x/tools/go/packages"
1416

1517
"github.com/golangci/golangci-lint/internal/go/cache"
@@ -156,12 +158,10 @@ func (c *Cache) packageHash(pkg *packages.Package, mode HashMode) (string, error
156158
curSum := key.Sum()
157159
hashRes[HashModeNeedOnlySelf] = hex.EncodeToString(curSum[:])
158160

159-
imps := make([]*packages.Package, 0, len(pkg.Imports))
160-
for _, imp := range pkg.Imports {
161-
imps = append(imps, imp)
162-
}
163-
sort.Slice(imps, func(i, j int) bool {
164-
return imps[i].PkgPath < imps[j].PkgPath
161+
imps := maps.Values(pkg.Imports)
162+
163+
slices.SortFunc(imps, func(a, b *packages.Package) int {
164+
return strings.Compare(a.PkgPath, b.PkgPath)
165165
})
166166

167167
calcDepsHash := func(depMode HashMode) error {

0 commit comments

Comments
 (0)