flag: replace sort.Slice with slices.SortFunc

Change-Id: I874f0c0399cb09de4fe4dd2097602c5fa0512b12
GitHub-Last-Rev: 73be01ae2a27adf0b7629a198057674018b5d392
GitHub-Pull-Request: golang/go#67223
Reviewed-on: https://go-review.googlesource.com/c/go/+/583735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
changes/35/583735/2
aimuz 2024-05-07 09:56:09 +00:00 committed by Gopher Robot
parent 709d6d5d22
commit 008cc58a11
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)
}
}