refactor(cmd): migrate sort.Slice to slices.SortFunc (bd-u2sc.2)
Modernize sorting code to use Go 1.21+ slices package: - Replace sort.Slice with slices.SortFunc across 16 files - Use cmp.Compare for orderable types (strings, ints) - Use time.Time.Compare for time comparisons - Use cmp.Or for multi-field sorting - Use slices.SortStableFunc where stability matters Benefits: cleaner 3-way comparison, slightly better performance, modern idiomatic Go. Part of GH#692 refactoring epic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"sort"
|
||||
"slices"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -130,8 +131,8 @@ func getContributorsSorted() []string {
|
||||
for name, commits := range beadsContributors {
|
||||
sorted = append(sorted, kv{name, commits})
|
||||
}
|
||||
sort.Slice(sorted, func(i, j int) bool {
|
||||
return sorted[i].commits > sorted[j].commits
|
||||
slices.SortFunc(sorted, func(a, b kv) int {
|
||||
return cmp.Compare(b.commits, a.commits) // descending order
|
||||
})
|
||||
names := make([]string, len(sorted))
|
||||
for i, kv := range sorted {
|
||||
|
||||
Reference in New Issue
Block a user