]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: use slices.Index
authorqiulaidongfeng <2645477756@qq.com>
Wed, 12 Feb 2025 16:41:13 +0000 (00:41 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 14 Feb 2025 15:04:42 +0000 (07:04 -0800)
Change-Id: Ifcab176faa2ac55e60576cf6acd96a18d0e860ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/648859
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/cmd/dist/build.go

index 1f467647f56143e98e00a950ae2a15d8759ba468..4fcc508f8ed48e0e934d37056ea70d27f05de4c3 100644 (file)
@@ -16,6 +16,7 @@ import (
        "os/exec"
        "path/filepath"
        "regexp"
+       "slices"
        "sort"
        "strconv"
        "strings"
@@ -104,16 +105,6 @@ var okgoos = []string{
        "aix",
 }
 
-// find reports the first index of p in l[0:n], or else -1.
-func find(p string, l []string) int {
-       for i, s := range l {
-               if p == s {
-                       return i
-               }
-       }
-       return -1
-}
-
 // xinit handles initialization of the various global state, like goroot and goarch.
 func xinit() {
        b := os.Getenv("GOROOT")
@@ -134,7 +125,7 @@ func xinit() {
                b = gohostos
        }
        goos = b
-       if find(goos, okgoos) < 0 {
+       if slices.Index(okgoos, goos) < 0 {
                fatalf("unknown $GOOS %s", goos)
        }
 
@@ -202,7 +193,7 @@ func xinit() {
        if b != "" {
                gohostarch = b
        }
-       if find(gohostarch, okgoarch) < 0 {
+       if slices.Index(okgoarch, gohostarch) < 0 {
                fatalf("unknown $GOHOSTARCH %s", gohostarch)
        }
 
@@ -211,7 +202,7 @@ func xinit() {
                b = gohostarch
        }
        goarch = b
-       if find(goarch, okgoarch) < 0 {
+       if slices.Index(okgoarch, goarch) < 0 {
                fatalf("unknown $GOARCH %s", goarch)
        }