Skip to content

Commit

Permalink
cmd/link/internal/ld: use strings.Cut
Browse files Browse the repository at this point in the history
Change-Id: I724fe76983ea259f12f073376d591c2f4b3c3d72
GitHub-Last-Rev: e61e865
GitHub-Pull-Request: golang#55910
Reviewed-on: https://go-review.googlesource.com/c/go/+/435738
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Run-TryBot: shuang cui <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
cuishuang authored and gopherbot committed Sep 22, 2023
1 parent 6d5c9f2 commit 9f8f1ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 3 additions & 7 deletions src/cmd/link/internal/ld/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions src/cmd/link/internal/ld/ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9f8f1ca

Please sign in to comment.