]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: use slices.Index
authorTobias Klauser <tklauser@distanz.ch>
Wed, 4 Sep 2024 11:31:19 +0000 (13:31 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 5 Sep 2024 18:54:24 +0000 (18:54 +0000)
Now that Go 1.22.6 is the minimum bootstrap toolchain (cf. CL 606156),
the slices package (introduced in Go 1.21) can be used in packages built
using the bootstrap toolchain.

For #64751

Change-Id: Ife0daa37c0982d9ec1afab07b9d40a1dfee9b7d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/610575
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/cgo/util.go

index 054cd6c5c729e9e9af7593b8dd4e0e42015cc2cc..23b4a414db75621bc281fff147ee6f861e4555c9 100644 (file)
@@ -10,13 +10,14 @@ import (
        "go/token"
        "os"
        "os/exec"
+       "slices"
 )
 
 // run runs the command argv, feeding in stdin on standard input.
 // It returns the output to standard output and standard error.
 // ok indicates whether the command exited successfully.
 func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
-       if i := find(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
+       if i := slices.Index(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
                // Some compilers have trouble with standard input.
                // Others have trouble with -xc.
                // Avoid both problems by writing a file with a .c extension.
@@ -69,15 +70,6 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
        return
 }
 
-func find(argv []string, target string) int {
-       for i, arg := range argv {
-               if arg == target {
-                       return i
-               }
-       }
-       return -1
-}
-
 func lineno(pos token.Pos) string {
        return fset.Position(pos).String()
 }