]> Cypherpunks repositories - gostls13.git/commitdiff
all: replace Split in loops with more efficient SplitSeq
authorcuishuang <imcusg@gmail.com>
Mon, 28 Apr 2025 09:04:20 +0000 (17:04 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 23 Oct 2025 14:34:31 +0000 (07:34 -0700)
Find these replacements through https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize.

Change-Id: If88fe0e109b7c7557bfb3d3ffc15271af1ab5856
Reviewed-on: https://go-review.googlesource.com/c/go/+/668437
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: David Chase <drchase@google.com>
src/compress/flate/example_test.go
src/go/ast/ast.go
src/log/slog/slogtest_test.go

index 578009248f5704d89eef7a3fb6adee2e4c6b8ecd..57e059f37a7ef340a54714f8c1647f95fbc3f3fb 100644 (file)
@@ -175,7 +175,7 @@ func Example_synchronization() {
                }
 
                b := make([]byte, 256)
-               for _, m := range strings.Fields("A long time ago in a galaxy far, far away...") {
+               for m := range strings.FieldsSeq("A long time ago in a galaxy far, far away...") {
                        // We use a simple framing format where the first byte is the
                        // message length, followed the message itself.
                        b[0] = uint8(copy(b[1:], m))
index 9aca39e868f3fe2e4856bbc494310fd960635096..a6dab5bb5171bc0a3931013a07dfd3c35fff43fe 100644 (file)
@@ -134,10 +134,10 @@ func (g *CommentGroup) Text() string {
                }
 
                // Split on newlines.
-               cl := strings.Split(c, "\n")
+               cl := strings.SplitSeq(c, "\n")
 
                // Walk lines, stripping trailing white space and adding to list.
-               for _, l := range cl {
+               for l := range cl {
                        lines = append(lines, stripTrailingWhitespace(l))
                }
        }
index 4887cc8c77d1e926f68271c660e1a26ff0b7061f..23b27de8bbce13484d4dc4f46cb40446765bf826 100644 (file)
@@ -43,7 +43,7 @@ func TestSlogtest(t *testing.T) {
 
 func parseLines(src []byte, parse func([]byte) (map[string]any, error)) ([]map[string]any, error) {
        var records []map[string]any
-       for _, line := range bytes.Split(src, []byte{'\n'}) {
+       for line := range bytes.SplitSeq(src, []byte{'\n'}) {
                if len(line) == 0 {
                        continue
                }