]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: use strings.CutPrefix
authorTobias Klauser <tklauser@distanz.ch>
Tue, 17 Sep 2024 07:57:01 +0000 (09:57 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 18 Sep 2024 15:07:34 +0000 (15:07 +0000)
Change-Id: Ie3f35183e88d544559743394c34b55483fdf59aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/613775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/cmd/cgo/gcc.go

index b2718ea7cce6b7c59a98920c6e623bd039c10e91..7ef6c170d1acb0e5de0a8d72d13490a0c8e8cdb3 100644 (file)
@@ -59,17 +59,17 @@ func cname(s string) string {
                return t
        }
 
-       if strings.HasPrefix(s, "struct_") {
-               return "struct " + s[len("struct_"):]
+       if t, ok := strings.CutPrefix(s, "struct_"); ok {
+               return "struct " + t
        }
-       if strings.HasPrefix(s, "union_") {
-               return "union " + s[len("union_"):]
+       if t, ok := strings.CutPrefix(s, "union_"); ok {
+               return "union " + t
        }
-       if strings.HasPrefix(s, "enum_") {
-               return "enum " + s[len("enum_"):]
+       if t, ok := strings.CutPrefix(s, "enum_"); ok {
+               return "enum " + t
        }
-       if strings.HasPrefix(s, "sizeof_") {
-               return "sizeof(" + cname(s[len("sizeof_"):]) + ")"
+       if t, ok := strings.CutPrefix(s, "sizeof_"); ok {
+               return "sizeof(" + cname(t) + ")"
        }
        return s
 }
@@ -1833,8 +1833,8 @@ func (p *Package) gccDebug(stdin []byte, nnames int) (d *dwarf.Data, ints []int6
                if strings.HasPrefix(s, "___") {
                        s = s[1:]
                }
-               if strings.HasPrefix(s, "__cgodebug_strlen__") {
-                       if n, err := strconv.Atoi(s[len("__cgodebug_strlen__"):]); err == nil {
+               if t, ok := strings.CutPrefix(s, "__cgodebug_strlen__"); ok {
+                       if n, err := strconv.Atoi(t); err == nil {
                                return n
                        }
                }