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>
This commit is contained in:
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" "os"
"reflect" "reflect"
"runtime" "runtime"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -420,8 +420,8 @@ func sortFlags(flags map[string]*Flag) []*Flag {
result[i] = f result[i] = f
i++ i++
} }
sort.Slice(result, func(i, j int) bool { slices.SortFunc(result, func(a, b *Flag) int {
return result[i].Name < result[j].Name return strings.Compare(a.Name, b.Name)
}) })
return result return result
} }

View File

@ -14,7 +14,7 @@ import (
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -101,7 +101,7 @@ func TestEverything(t *testing.T) {
// Now test they're visited in sort order. // Now test they're visited in sort order.
var flagNames []string var flagNames []string
Visit(func(f *Flag) { flagNames = append(flagNames, f.Name) }) 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) t.Errorf("flag names not sorted: %v", flagNames)
} }
} }