]> Cypherpunks repositories - gostls13.git/commitdiff
flag: replace sort.Slice with slices.SortFunc
authoraimuz <mr.imuz@gmail.com>
Tue, 7 May 2024 09:56:09 +0000 (09:56 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 7 May 2024 18:38:24 +0000 (18:38 +0000)
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>
src/flag/flag.go
src/flag/flag_test.go

index 1669e9aca7f2f334bf2d987dcb6796d7f58c797a..4fa502839ada550fcdbca079970d5b7205dd4d6c 100644 (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
 }
index 8e9ae316fe0e7dbbe234d7b44992dec734ff9cc5..14a5038917f21b24e320d4eff91c64342d89df2c 100644 (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)
        }
 }