1
0
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:
aimuz 2024-05-07 17:38:24 +08:00
parent 619b419a4b
commit 73be01ae2a
2 changed files with 5 additions and 5 deletions

View File

@ -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
}

View File

@ -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)
}
}