Skip to content

Commit 6cce191

Browse files
tklausergopherbot
authored andcommitted
cmd/cgo: use strings.CutPrefix
Change-Id: Ie3f35183e88d544559743394c34b55483fdf59aa Reviewed-on: https://go-review.googlesource.com/c/go/+/613775 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 3dc146d commit 6cce191

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/cmd/cgo/gcc.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ func cname(s string) string {
5959
return t
6060
}
6161

62-
if strings.HasPrefix(s, "struct_") {
63-
return "struct " + s[len("struct_"):]
62+
if t, ok := strings.CutPrefix(s, "struct_"); ok {
63+
return "struct " + t
6464
}
65-
if strings.HasPrefix(s, "union_") {
66-
return "union " + s[len("union_"):]
65+
if t, ok := strings.CutPrefix(s, "union_"); ok {
66+
return "union " + t
6767
}
68-
if strings.HasPrefix(s, "enum_") {
69-
return "enum " + s[len("enum_"):]
68+
if t, ok := strings.CutPrefix(s, "enum_"); ok {
69+
return "enum " + t
7070
}
71-
if strings.HasPrefix(s, "sizeof_") {
72-
return "sizeof(" + cname(s[len("sizeof_"):]) + ")"
71+
if t, ok := strings.CutPrefix(s, "sizeof_"); ok {
72+
return "sizeof(" + cname(t) + ")"
7373
}
7474
return s
7575
}
@@ -1833,8 +1833,8 @@ func (p *Package) gccDebug(stdin []byte, nnames int) (d *dwarf.Data, ints []int6
18331833
if strings.HasPrefix(s, "___") {
18341834
s = s[1:]
18351835
}
1836-
if strings.HasPrefix(s, "__cgodebug_strlen__") {
1837-
if n, err := strconv.Atoi(s[len("__cgodebug_strlen__"):]); err == nil {
1836+
if t, ok := strings.CutPrefix(s, "__cgodebug_strlen__"); ok {
1837+
if n, err := strconv.Atoi(t); err == nil {
18381838
return n
18391839
}
18401840
}

0 commit comments

Comments
 (0)