From ca448191c9dd3acd47ba8439e5e9bc36ae21417f Mon Sep 17 00:00:00 2001 From: cuishuang Date: Mon, 28 Apr 2025 17:04:20 +0800 Subject: [PATCH] all: replace Split in loops with more efficient SplitSeq 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Auto-Submit: Sean Liao Reviewed-by: David Chase --- src/compress/flate/example_test.go | 2 +- src/go/ast/ast.go | 4 ++-- src/log/slog/slogtest_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compress/flate/example_test.go b/src/compress/flate/example_test.go index 578009248f..57e059f37a 100644 --- a/src/compress/flate/example_test.go +++ b/src/compress/flate/example_test.go @@ -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)) diff --git a/src/go/ast/ast.go b/src/go/ast/ast.go index 9aca39e868..a6dab5bb51 100644 --- a/src/go/ast/ast.go +++ b/src/go/ast/ast.go @@ -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)) } } diff --git a/src/log/slog/slogtest_test.go b/src/log/slog/slogtest_test.go index 4887cc8c77..23b27de8bb 100644 --- a/src/log/slog/slogtest_test.go +++ b/src/log/slog/slogtest_test.go @@ -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 } -- 2.52.0