Skip to content

Commit 634363e

Browse files
tklausergopherbot
authored andcommitted
cmd/cgo: use slices.Index
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 <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent c3f1630 commit 634363e

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/cmd/cgo/util.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
"go/token"
1111
"os"
1212
"os/exec"
13+
"slices"
1314
)
1415

1516
// run runs the command argv, feeding in stdin on standard input.
1617
// It returns the output to standard output and standard error.
1718
// ok indicates whether the command exited successfully.
1819
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
19-
if i := find(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
20+
if i := slices.Index(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
2021
// Some compilers have trouble with standard input.
2122
// Others have trouble with -xc.
2223
// 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) {
6970
return
7071
}
7172

72-
func find(argv []string, target string) int {
73-
for i, arg := range argv {
74-
if arg == target {
75-
return i
76-
}
77-
}
78-
return -1
79-
}
80-
8173
func lineno(pos token.Pos) string {
8274
return fset.Position(pos).String()
8375
}

0 commit comments

Comments
 (0)