Skip to content

Commit 361f5eb

Browse files
cuishuangbsiegert
authored andcommitted
all: use strings.CutPrefix
Updates #42537 Change-Id: Ice23d7d36bbede27551cbc086119694f6a3b5e4a GitHub-Last-Rev: 0d65208 GitHub-Pull-Request: #55347 Reviewed-on: https://go-review.googlesource.com/c/go/+/432895 Reviewed-by: Benny Siegert <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 17f83e3 commit 361f5eb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/go/build/build.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ func hasSubdir(root, dir string) (rel string, ok bool) {
179179
root += sep
180180
}
181181
dir = filepath.Clean(dir)
182-
if !strings.HasPrefix(dir, root) {
182+
after, found := strings.CutPrefix(dir, root)
183+
if !found {
183184
return "", false
184185
}
185-
return filepath.ToSlash(dir[len(root):]), true
186+
return filepath.ToSlash(after), true
186187
}
187188

188189
// readDir calls ctxt.ReadDir (if not nil) or else os.ReadDir.

src/go/printer/comment.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ func formatDocComment(list []*ast.Comment) []*ast.Comment {
3636
kind = "//"
3737
var b strings.Builder
3838
for _, c := range list {
39-
if !strings.HasPrefix(c.Text, "//") {
39+
after, found := strings.CutPrefix(c.Text, "//")
40+
if !found {
4041
return list
4142
}
4243
// Accumulate //go:build etc lines separately.
43-
if isDirective(c.Text[2:]) {
44+
if isDirective(after) {
4445
directives = append(directives, c)
4546
continue
4647
}
47-
b.WriteString(strings.TrimPrefix(c.Text[2:], " "))
48+
b.WriteString(strings.TrimPrefix(after, " "))
4849
b.WriteString("\n")
4950
}
5051
text = b.String()

0 commit comments

Comments
 (0)