Skip to content

Commit ba63d13

Browse files
kolyshkingopherbot
authored andcommitted
all: use strings.SplitSeq/FieldSeq
Replace Split in "for range strings.Split(...)" by go1.24's more efficient SplitSeq, or Fields with FieldSeq. Generated by modernize -fix -test -category stringsseq ./... (with a few minor edits on top to remove intermediate vars). Change-Id: Ifd616ccec14e7fe0a743d427e02f44b3297a273c Reviewed-on: https://go-review.googlesource.com/c/tools/+/703075 Auto-Submit: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 3ab2909 commit ba63d13

File tree

25 files changed

+26
-28
lines changed

25 files changed

+26
-28
lines changed

cmd/bundle/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func bundle(src, dst, dstpkg, prefix, buildTags string) ([]byte, error) {
241241
// Concatenate package comments from all files...
242242
for _, f := range pkg.Syntax {
243243
if doc := f.Doc.Text(); strings.TrimSpace(doc) != "" {
244-
for _, line := range strings.Split(doc, "\n") {
244+
for line := range strings.SplitSeq(doc, "\n") {
245245
fmt.Fprintf(&out, "// %s\n", line)
246246
}
247247
}

cmd/compilebench/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func runBuildCmd(name string, count int, dir, tool string, args []string) error
511511
if err != nil {
512512
log.Print("cannot find memory profile after compilation")
513513
}
514-
for _, line := range strings.Split(string(out), "\n") {
514+
for line := range strings.SplitSeq(string(out), "\n") {
515515
f := strings.Fields(line)
516516
if len(f) < 4 || f[0] != "#" || f[2] != "=" {
517517
continue

cmd/digraph/digraph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestSomepath(t *testing.T) {
252252
got = strings.Join(lines[1:], "\n")
253253

254254
var oneMatch bool
255-
for _, want := range strings.Split(test.wantAnyOf, "|") {
255+
for want := range strings.SplitSeq(test.wantAnyOf, "|") {
256256
if got == want {
257257
oneMatch = true
258258
}

cmd/fiximports/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func fiximports(packages ...string) bool {
175175
matchPrefix bool
176176
}
177177
var replace []replaceItem
178-
for _, pair := range strings.Split(*replaceFlag, ",") {
178+
for pair := range strings.SplitSeq(*replaceFlag, ",") {
179179
if pair == "" {
180180
continue
181181
}

cmd/go-contrib-init/contrib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func checkGitOrigin() {
191191
log.Fatalf("Error running git remote -v: %v", msg)
192192
}
193193
matches := 0
194-
for _, line := range strings.Split(string(remotes), "\n") {
194+
for line := range strings.SplitSeq(string(remotes), "\n") {
195195
line = strings.TrimSpace(line)
196196
if !strings.HasPrefix(line, "origin") {
197197
continue

cmd/html2article/conv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func isBoldTitle(s string) bool {
132132
}
133133

134134
func indent(buf *bytes.Buffer, s string) {
135-
for _, l := range strings.Split(s, "\n") {
135+
for l := range strings.SplitSeq(s, "\n") {
136136
if l != "" {
137137
buf.WriteByte('\t')
138138
buf.WriteString(l)
@@ -143,7 +143,7 @@ func indent(buf *bytes.Buffer, s string) {
143143

144144
func unwrap(buf *bytes.Buffer, s string) {
145145
var cont bool
146-
for _, l := range strings.Split(s, "\n") {
146+
for l := range strings.SplitSeq(s, "\n") {
147147
l = strings.TrimSpace(l)
148148
if len(l) == 0 {
149149
if cont {

cmd/present2md/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func printSectionBody(file string, depth int, w *bytes.Buffer, elems []present.E
200200
lines = lines[1:]
201201
}
202202
if elem.Pre {
203-
for _, line := range strings.Split(strings.TrimRight(elem.Raw, "\n"), "\n") {
203+
for line := range strings.SplitSeq(strings.TrimRight(elem.Raw, "\n"), "\n") {
204204
if line == "" {
205205
fmt.Fprintf(w, "\n")
206206
} else {

cmd/signature-fuzzer/internal/fuzz-generator/generator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ func ParseMaskString(arg string, tag string) (map[int]int, error) {
409409
}
410410
verb(1, "%s mask is %s", tag, arg)
411411
m := make(map[int]int)
412-
ss := strings.Split(arg, ":")
413-
for _, s := range ss {
412+
for s := range strings.SplitSeq(arg, ":") {
414413
if strings.Contains(s, "-") {
415414
rng := strings.Split(s, "-")
416415
if len(rng) != 2 {

go/analysis/analysistest/analysistest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func check(t Testing, gopath string, act *checker.Action) {
590590
}
591591
filename := sanitize(gopath, filename)
592592
linenum := 0
593-
for _, line := range strings.Split(string(data), "\n") {
593+
for line := range strings.SplitSeq(string(data), "\n") {
594594
linenum++
595595

596596
// Hack: treat a comment of the form "//...// want..."

go/analysis/internal/checker/fix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func TestScript(t *testing.T) {
338338

339339
case "skip":
340340
config := fmt.Sprintf("GOOS=%s GOARCH=%s", runtime.GOOS, runtime.GOARCH)
341-
for _, word := range strings.Fields(rest) {
341+
for word := range strings.FieldsSeq(rest) {
342342
if strings.Contains(config, word) {
343343
t.Skip(word)
344344
}

0 commit comments

Comments
 (0)