Skip to content

Commit

Permalink
cmd/cgo: use slices.Index
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tklauser authored and gopherbot committed Sep 5, 2024
1 parent c3f1630 commit 634363e
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/cmd/cgo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 634363e

Please sign in to comment.