Skip to content

Commit

Permalink
refactor: be less clever
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 30, 2024
1 parent 51f46f1 commit 6e3020f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions internal/output/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ func (pss *pkgSourceSet) StableKeys() []pkgWithSource {
pkgWithSrcKeys := maps.Keys(*pss)

slices.SortFunc(pkgWithSrcKeys, func(a, b pkgWithSource) int {
for _, fn := range []func() int{
func() int { return strings.Compare(a.Source.Path, b.Source.Path) },
func() int { return strings.Compare(a.Package.Name, b.Package.Name) },
func() int { return strings.Compare(a.Package.Version, b.Package.Version) },
} {
if r := fn(); r != 0 {
return r
}
var r int

r = strings.Compare(a.Source.Path, b.Source.Path)
if r != 0 {
return r
}

r = strings.Compare(a.Package.Name, b.Package.Name)
if r != 0 {
return r
}

r = strings.Compare(a.Package.Version, b.Package.Version)
if r != 0 {
return r
}

return 0
return r
})

return pkgWithSrcKeys
Expand Down

0 comments on commit 6e3020f

Please sign in to comment.