Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9f8f1ca

Browse files
cuishuanggopherbot
authored andcommitted
cmd/link/internal/ld: use strings.Cut
Change-Id: I724fe76983ea259f12f073376d591c2f4b3c3d72 GitHub-Last-Rev: e61e865 GitHub-Pull-Request: #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>
1 parent 6d5c9f2 commit 9f8f1ca

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

‎src/cmd/link/internal/ld/go.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, filename s
5050
// process header lines
5151
for data != "" {
5252
var line string
53-
if i := strings.Index(data, "\n"); i >= 0 {
54-
line, data = data[:i], data[i+1:]
55-
} else {
56-
line, data = data, ""
57-
}
53+
line, data, _ = strings.Cut(data, "\n")
5854
if line == "main" {
5955
lib.Main = true
6056
}
@@ -141,8 +137,8 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, host
141137
}
142138

143139
q := ""
144-
if i:= strings.Index(remote, "#"); i>=0 {
145-
remote, q = remote[:i], remote[i+1:]
140+
if before, after, found:= strings.Cut(remote, "#"); found {
141+
remote, q = before, after
146142
}
147143
s := l.LookupOrCreateSym(local, 0)
148144
st := l.SymType(s)

‎src/cmd/link/internal/ld/ld.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ func (ctxt *Link) readImportCfg(file string) {
6262
continue
6363
}
6464

65-
var verb, args string
66-
if i := strings.Index(line, " "); i < 0 {
67-
verb = line
68-
} else {
69-
verb, args = line[:i], strings.TrimSpace(line[i+1:])
65+
verb, args, found := strings.Cut(line, " ")
66+
if found {
67+
args = strings.TrimSpace(args)
7068
}
71-
varbefore, afterstring
72-
if i:=strings.Index(args, "="); i>=0 {
73-
before, after=args[:i], args[i+1:]
69+
before, after, exist:=strings.Cut(args, "=")
70+
if !exist {
71+
before=""
7472
}
7573
switch verb {
7674
default:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /