cmd/link/internal/ld: use strings.Cut

Change-Id: I724fe76983ea259f12f073376d591c2f4b3c3d72
GitHub-Last-Rev: e61e865ba97a52d24d3aee7642f5804916e94544
GitHub-Pull-Request: golang/go#55910
Reviewed-on: https://go-review.googlesource.com/c/go/+/435738
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: shuang cui <imcusg@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
cui fliter 2023-09-22 14:24:33 +00:00 committed by Gopher Robot
parent 6d5c9f2f26
commit 9f8f1ca5ad
2 changed files with 9 additions and 15 deletions

View File

@ -50,11 +50,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, filename s
// process header lines
for data != "" {
var line string
if i := strings.Index(data, "\n"); i >= 0 {
line, data = data[:i], data[i+1:]
} else {
line, data = data, ""
}
line, data, _ = strings.Cut(data, "\n")
if line == "main" {
lib.Main = true
}
@ -141,8 +137,8 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, host
}
q := ""
if i := strings.Index(remote, "#"); i >= 0 {
remote, q = remote[:i], remote[i+1:]
if before, after, found := strings.Cut(remote, "#"); found {
remote, q = before, after
}
s := l.LookupOrCreateSym(local, 0)
st := l.SymType(s)

View File

@ -62,15 +62,13 @@ func (ctxt *Link) readImportCfg(file string) {
continue
}
var verb, args string
if i := strings.Index(line, " "); i < 0 {
verb = line
} else {
verb, args = line[:i], strings.TrimSpace(line[i+1:])
verb, args, found := strings.Cut(line, " ")
if found {
args = strings.TrimSpace(args)
}
var before, after string
if i := strings.Index(args, "="); i >= 0 {
before, after = args[:i], args[i+1:]
before, after, exist := strings.Cut(args, "=")
if !exist {
before = ""
}
switch verb {
default: