mirror of
https://github.com/golang/go
synced 2024-11-11 17:51:49 -07:00
cmd/cgo: use slices.ContainsFunc
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: Ib36f39016f57c5e110f78a85ca9c806d91356024 Reviewed-on: https://go-review.googlesource.com/c/go/+/612316 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
ad6ee21bbf
commit
9deda35ff8
@ -24,6 +24,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
@ -781,16 +782,13 @@ func (p *Package) mangleName(n *Name) {
|
||||
}
|
||||
|
||||
func (f *File) isMangledName(s string) bool {
|
||||
prefix := "_C"
|
||||
if strings.HasPrefix(s, prefix) {
|
||||
t := s[len(prefix):]
|
||||
for _, k := range nameKinds {
|
||||
if strings.HasPrefix(t, k+"_") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
t, ok := strings.CutPrefix(s, "_C")
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(nameKinds, func(k string) bool {
|
||||
return strings.HasPrefix(t, k+"_")
|
||||
})
|
||||
}
|
||||
|
||||
// rewriteCalls rewrites all calls that pass pointers to check that
|
||||
@ -1050,12 +1048,9 @@ func (p *Package) hasPointer(f *File, t ast.Expr, top bool) bool {
|
||||
}
|
||||
return p.hasPointer(f, t.Elt, top)
|
||||
case *ast.StructType:
|
||||
for _, field := range t.Fields.List {
|
||||
if p.hasPointer(f, field.Type, top) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(t.Fields.List, func(field *ast.Field) bool {
|
||||
return p.hasPointer(f, field.Type, top)
|
||||
})
|
||||
case *ast.StarExpr: // Pointer type.
|
||||
if !top {
|
||||
return true
|
||||
@ -3202,12 +3197,9 @@ func (c *typeConv) dwarfHasPointer(dt dwarf.Type, pos token.Pos) bool {
|
||||
return c.dwarfHasPointer(dt.Type, pos)
|
||||
|
||||
case *dwarf.StructType:
|
||||
for _, f := range dt.Field {
|
||||
if c.dwarfHasPointer(f.Type, pos) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(dt.Field, func(f *dwarf.StructField) bool {
|
||||
return c.dwarfHasPointer(f.Type, pos)
|
||||
})
|
||||
|
||||
case *dwarf.TypedefType:
|
||||
if dt.Name == "_GoString_" || dt.Name == "_GoBytes_" {
|
||||
|
Loading…
Reference in New Issue
Block a user