From 634363e3cab412ae7c40b46fde9f29034251c35c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 4 Sep 2024 13:31:19 +0200 Subject: [PATCH] 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 Auto-Submit: Tobias Klauser LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/util.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/cmd/cgo/util.go b/src/cmd/cgo/util.go index 054cd6c5c72..23b4a414db7 100644 --- a/src/cmd/cgo/util.go +++ b/src/cmd/cgo/util.go @@ -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() }