[go] all: replace ranging over Split/Fields with SplitSeq/FieldsSeq

3 views
Skip to first unread message

Kirill Kolyshkin (Gerrit)

unread,
Dec 17, 2025, 8:03:31 PM (2 days ago) Dec 17
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Kirill Kolyshkin has uploaded the change for review

Commit message

all: replace ranging over Split/Fields with SplitSeq/FieldsSeq

Improve the efficiency of iterating over substrings, replacing
strings.Split with the more efficient strings.SplitSeq, which
was added in Go 1.24 and avoids allocating a slice for the substrings.
Do the similar thing with strings.Fields.

Generated by

go fix -stringsseq ./...

using

go version go1.26-devel_ad85395442 Wed Dec 17 15:56:48 2025 -0800 linux/amd64
Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0

Change diff

diff --git a/src/crypto/internal/fips140deps/fipsdeps_test.go b/src/crypto/internal/fips140deps/fipsdeps_test.go
index e2d1d18..80ddc38 100644
--- a/src/crypto/internal/fips140deps/fipsdeps_test.go
+++ b/src/crypto/internal/fips140deps/fipsdeps_test.go
@@ -64,7 +64,7 @@
// importCheck is the set of packages that import crypto/internal/fips140/check.
importCheck := make(map[string]bool)

- for _, line := range strings.Split(out, "\n") {
+ for line := range strings.SplitSeq(out, "\n") {
if line == "" {
continue
}
diff --git a/src/crypto/purego_test.go b/src/crypto/purego_test.go
index ebc9110..14e2272 100644
--- a/src/crypto/purego_test.go
+++ b/src/crypto/purego_test.go
@@ -35,7 +35,7 @@
log.Fatalf("loading architecture list: %v\n%s", err, out)
}
allGOARCH := make(map[string]bool)
- for _, pair := range strings.Split(strings.TrimSpace(string(out)), "\n") {
+ for pair := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") {
GOARCH := strings.Split(pair, "/")[1]
allGOARCH[GOARCH] = true
}
diff --git a/src/crypto/tls/handshake_test.go b/src/crypto/tls/handshake_test.go
index 7191ced..2394ee5 100644
--- a/src/crypto/tls/handshake_test.go
+++ b/src/crypto/tls/handshake_test.go
@@ -212,8 +212,8 @@
}
line = before

- hexBytes := strings.Fields(line)
- for _, hexByte := range hexBytes {
+ hexBytes := strings.FieldsSeq(line)
+ for hexByte := range hexBytes {
val, err := strconv.ParseUint(hexByte, 16, 8)
if err != nil {
return nil, errors.New("invalid hex byte in test data: " + err.Error())
diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
index e5f0459..612ed95 100644
--- a/src/database/sql/fakedb_test.go
+++ b/src/database/sql/fakedb_test.go
@@ -633,7 +633,7 @@

c.touchMem()
var firstStmt, prev *fakeStmt
- for _, query := range strings.Split(query, ";") {
+ for query := range strings.SplitSeq(query, ";") {
parts := strings.Split(query, "|")
if len(parts) < 1 {
return nil, errf("empty query")
diff --git a/src/flag/example_test.go b/src/flag/example_test.go
index 088447d..36bb0a2 100644
--- a/src/flag/example_test.go
+++ b/src/flag/example_test.go
@@ -51,7 +51,7 @@
if len(*i) > 0 {
return errors.New("interval flag already set")
}
- for _, dt := range strings.Split(value, ",") {
+ for dt := range strings.SplitSeq(value, ",") {
duration, err := time.ParseDuration(dt)
if err != nil {
return err
diff --git a/src/go/build/constraint/expr_test.go b/src/go/build/constraint/expr_test.go
index f0d0895..eed049f 100644
--- a/src/go/build/constraint/expr_test.go
+++ b/src/go/build/constraint/expr_test.go
@@ -188,7 +188,7 @@
}
tags := make(map[string]bool)
wantTags := make(map[string]bool)
- for _, tag := range strings.Fields(tt.tags) {
+ for tag := range strings.FieldsSeq(tt.tags) {
wantTags[tag] = true
}
hasTag := func(tag string) bool {
diff --git a/src/go/build/vendor_test.go b/src/go/build/vendor_test.go
index 7f6237f..2e5c40a 100644
--- a/src/go/build/vendor_test.go
+++ b/src/go/build/vendor_test.go
@@ -33,7 +33,7 @@
if err != nil {
t.Fatal(err)
}
- for _, fullPkg := range strings.Split(string(out), "\n") {
+ for fullPkg := range strings.SplitSeq(string(out), "\n") {
pkg, found := strings.CutPrefix(fullPkg, "vendor/")
if !found {
_, pkg, found = strings.Cut(fullPkg, "/vendor/")
diff --git a/src/go/doc/comment/std_test.go b/src/go/doc/comment/std_test.go
index 9077af0..de7f01c 100644
--- a/src/go/doc/comment/std_test.go
+++ b/src/go/doc/comment/std_test.go
@@ -21,7 +21,7 @@
}

var list []string
- for _, pkg := range strings.Fields(string(out)) {
+ for pkg := range strings.FieldsSeq(string(out)) {
if !strings.Contains(pkg, "/") {
list = append(list, pkg)
}
diff --git a/src/internal/fuzz/pcg.go b/src/internal/fuzz/pcg.go
index a6fa42f..89d9626 100644
--- a/src/internal/fuzz/pcg.go
+++ b/src/internal/fuzz/pcg.go
@@ -42,8 +42,8 @@
}

func godebugSeed() *int {
- debug := strings.Split(os.Getenv("GODEBUG"), ",")
- for _, f := range debug {
+ debug := strings.SplitSeq(os.Getenv("GODEBUG"), ",")
+ for f := range debug {
if after, ok := strings.CutPrefix(f, "fuzzseed="); ok {
seed, err := strconv.Atoi(after)
if err != nil {
diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go
index f83d792..581129c 100644
--- a/src/internal/godebug/godebug_test.go
+++ b/src/internal/godebug/godebug_test.go
@@ -120,7 +120,7 @@
slices.Sort(want)

var have []string
- for _, line := range strings.Split(string(out), "\n") {
+ for line := range strings.SplitSeq(string(out), "\n") {
if strings.Contains(line, "godebug_test.go:") {
have = append(have, line[strings.LastIndex(line, "godebug_test.go:"):])
}
diff --git a/src/internal/godebugs/godebugs_test.go b/src/internal/godebugs/godebugs_test.go
index e242f58..9fef9dc 100644
--- a/src/internal/godebugs/godebugs_test.go
+++ b/src/internal/godebugs/godebugs_test.go
@@ -69,7 +69,7 @@
}

seen := map[string]bool{}
- for _, dir := range strings.Split(string(out), "\n") {
+ for dir := range strings.SplitSeq(string(out), "\n") {
if dir == "" {
continue
}
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go
index 96eacc6..1945994 100644
--- a/src/internal/testenv/testenv.go
+++ b/src/internal/testenv/testenv.go
@@ -174,7 +174,7 @@
// Add all environment variables that affect the Go command to test metadata.
// Cached test results will be invalidate when these variables change.
// See golang.org/issue/32285.
- for _, envVar := range strings.Fields(cfg.KnownEnv) {
+ for envVar := range strings.FieldsSeq(cfg.KnownEnv) {
os.Getenv(envVar)
}
return path
diff --git a/src/math/rand/v2/regress_test.go b/src/math/rand/v2/regress_test.go
index e808b25..7028fe0 100644
--- a/src/math/rand/v2/regress_test.go
+++ b/src/math/rand/v2/regress_test.go
@@ -182,7 +182,7 @@

var buf bytes.Buffer
fmt.Fprintf(&buf, "\t// Output:\n")
- for _, line := range strings.Split(string(out), "\n") {
+ for line := range strings.SplitSeq(string(out), "\n") {
if line != "" {
fmt.Fprintf(&buf, "\t// %s\n", line)
}
diff --git a/src/net/http/example_filesystem_test.go b/src/net/http/example_filesystem_test.go
index da1f0df..233108e 100644
--- a/src/net/http/example_filesystem_test.go
+++ b/src/net/http/example_filesystem_test.go
@@ -16,8 +16,8 @@
// The name is assumed to be a delimited by forward slashes, as guaranteed
// by the http.FileSystem interface.
func containsDotFile(name string) bool {
- parts := strings.Split(name, "/")
- for _, part := range parts {
+ parts := strings.SplitSeq(name, "/")
+ for part := range parts {
if strings.HasPrefix(part, ".") {
return true
}
diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go
index f1d8577..c41c18a 100644
--- a/src/runtime/pprof/pprof_test.go
+++ b/src/runtime/pprof/pprof_test.go
@@ -759,7 +759,7 @@

// stackContainsAll matches if all functions in spec (comma-separated) appear somewhere in the stack trace.
func stackContainsAll(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool {
- for _, f := range strings.Split(spec, ",") {
+ for f := range strings.SplitSeq(spec, ",") {
if !stackContains(f, count, stk, labels) {
return false
}
diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go
index 8ec47a4..a160d10 100644
--- a/src/syscall/syscall_linux_test.go
+++ b/src/syscall/syscall_linux_test.go
@@ -428,8 +428,8 @@
// "... : bad file descriptor.
continue
}
- lines := strings.Split(string(d), "\n")
- for _, line := range lines {
+ lines := strings.SplitSeq(string(d), "\n")
+ for line := range lines {
// Different kernel vintages pad differently.
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "Pid:\t") {
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index 5340c50..4d0ca99 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -1142,7 +1142,7 @@
t.Fatalf("want artifact directory contained in %q, got %q", outputDir, artifactDir)
}

- for _, part := range strings.Split(relDir, string(os.PathSeparator)) {
+ for part := range strings.SplitSeq(relDir, string(os.PathSeparator)) {
const maxSize = 64
if len(part) > maxSize {
t.Errorf("artifact directory %q contains component >%v characters long: %q", relDir, maxSize, part)

Change information

Files:
  • M src/crypto/internal/fips140deps/fipsdeps_test.go
  • M src/crypto/purego_test.go
  • M src/crypto/tls/handshake_test.go
  • M src/database/sql/fakedb_test.go
  • M src/flag/example_test.go
  • M src/go/build/constraint/expr_test.go
  • M src/go/build/vendor_test.go
  • M src/go/doc/comment/std_test.go
  • M src/internal/fuzz/pcg.go
  • M src/internal/godebug/godebug_test.go
  • M src/internal/godebugs/godebugs_test.go
  • M src/internal/testenv/testenv.go
  • M src/math/rand/v2/regress_test.go
  • M src/net/http/example_filesystem_test.go
  • M src/runtime/pprof/pprof_test.go
  • M src/syscall/syscall_linux_test.go
  • M src/testing/testing_test.go
Change size: S
Delta: 17 files changed, 21 insertions(+), 21 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0
Gerrit-Change-Number: 730964
Gerrit-PatchSet: 1
Gerrit-Owner: Kirill Kolyshkin <koly...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Griesemer (Gerrit)

unread,
Dec 18, 2025, 12:46:36 PM (22 hours ago) Dec 18
to Kirill Kolyshkin, goph...@pubsubhelper.golang.org, Filippo Valsorda, Roland Shoemaker, Russ Cox, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Filippo Valsorda, Kirill Kolyshkin, Roland Shoemaker and Russ Cox

Robert Griesemer voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Filippo Valsorda
  • Kirill Kolyshkin
  • Roland Shoemaker
  • Russ Cox
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0
Gerrit-Change-Number: 730964
Gerrit-PatchSet: 1
Gerrit-Owner: Kirill Kolyshkin <koly...@gmail.com>
Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Russ Cox <r...@golang.org>
Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
Gerrit-Attention: Kirill Kolyshkin <koly...@gmail.com>
Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
Gerrit-Comment-Date: Thu, 18 Dec 2025 17:46:31 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Griesemer (Gerrit)

unread,
Dec 18, 2025, 12:48:39 PM (22 hours ago) Dec 18
to Kirill Kolyshkin, goph...@pubsubhelper.golang.org, Russ Cox, Go LUCI, Filippo Valsorda, Roland Shoemaker, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Filippo Valsorda, Kirill Kolyshkin and Roland Shoemaker

Robert Griesemer removed Russ Cox from this change

Deleted Reviewers:
  • Russ Cox
Open in Gerrit

Related details

Attention is currently required from:
  • Filippo Valsorda
  • Kirill Kolyshkin
  • Roland Shoemaker
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: deleteReviewer
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0
Gerrit-Change-Number: 730964
Gerrit-PatchSet: 1
Gerrit-Owner: Kirill Kolyshkin <koly...@gmail.com>
Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Kirill Kolyshkin (Gerrit)

unread,
Dec 18, 2025, 4:10:18 PM (19 hours ago) Dec 18
to goph...@pubsubhelper.golang.org, Go LUCI, Robert Griesemer, Filippo Valsorda, Roland Shoemaker, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Filippo Valsorda, Robert Griesemer and Roland Shoemaker

Kirill Kolyshkin voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Filippo Valsorda
  • Robert Griesemer
  • Roland Shoemaker
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0
Gerrit-Change-Number: 730964
Gerrit-PatchSet: 2
Gerrit-Owner: Kirill Kolyshkin <koly...@gmail.com>
Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
Gerrit-Reviewer: Kirill Kolyshkin <koly...@gmail.com>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Robert Griesemer <g...@google.com>
Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
Gerrit-Comment-Date: Thu, 18 Dec 2025 21:10:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Kirill Kolyshkin (Gerrit)

unread,
Dec 18, 2025, 8:05:41 PM (15 hours ago) Dec 18
to goph...@pubsubhelper.golang.org, Go LUCI, Robert Griesemer, Filippo Valsorda, Roland Shoemaker, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Filippo Valsorda, Robert Griesemer and Roland Shoemaker

Kirill Kolyshkin voted and added 1 comment

Votes added by Kirill Kolyshkin

Hold+1

1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Kirill Kolyshkin . resolved

Hold for Go 1.26 freeze

Open in Gerrit

Related details

Attention is currently required from:
  • Filippo Valsorda
  • Robert Griesemer
  • Roland Shoemaker
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Holds
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I172611b9349c07a8f4f2bb564e9cd44402aa8fa0
    Gerrit-Change-Number: 730964
    Gerrit-PatchSet: 2
    Gerrit-Owner: Kirill Kolyshkin <koly...@gmail.com>
    Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
    Gerrit-Reviewer: Kirill Kolyshkin <koly...@gmail.com>
    Gerrit-Reviewer: Robert Griesemer <g...@google.com>
    Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
    Gerrit-Comment-Date: Fri, 19 Dec 2025 01:05:35 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages