mirror of
https://github.com/golang/go
synced 2024-11-15 02:40:32 -07:00
flag: replace sort.Slice with slices.SortFunc
This commit is contained in:
parent
619b419a4b
commit
73be01ae2a
@ -90,7 +90,7 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -420,8 +420,8 @@ func sortFlags(flags map[string]*Flag) []*Flag {
|
||||
result[i] = f
|
||||
i++
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].Name < result[j].Name
|
||||
slices.SortFunc(result, func(a, b *Flag) int {
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -101,7 +101,7 @@ func TestEverything(t *testing.T) {
|
||||
// Now test they're visited in sort order.
|
||||
var flagNames []string
|
||||
Visit(func(f *Flag) { flagNames = append(flagNames, f.Name) })
|
||||
if !sort.StringsAreSorted(flagNames) {
|
||||
if !slices.IsSorted(flagNames) {
|
||||
t.Errorf("flag names not sorted: %v", flagNames)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user