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:
+4
-3
@@ -1,13 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -116,8 +117,8 @@ func selectNextTip(store storage.Storage) *Tip {
|
||||
}
|
||||
|
||||
// Sort by priority (highest first)
|
||||
sort.Slice(eligibleTips, func(i, j int) bool {
|
||||
return eligibleTips[i].Priority > eligibleTips[j].Priority
|
||||
slices.SortFunc(eligibleTips, func(a, b Tip) int {
|
||||
return cmp.Compare(b.Priority, a.Priority) // descending order
|
||||
})
|
||||
|
||||
// Apply probability roll (in priority order)
|
||||
|
||||
Reference in New Issue
Block a user