Skip to content

Commit ca44819

Browse files
cuishuanggopherbot
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Sean Liao <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 107fcb7 commit ca44819

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/compress/flate/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func Example_synchronization() {
175175
}
176176

177177
b := make([]byte, 256)
178-
for _, m := range strings.Fields("A long time ago in a galaxy far, far away...") {
178+
for m := range strings.FieldsSeq("A long time ago in a galaxy far, far away...") {
179179
// We use a simple framing format where the first byte is the
180180
// message length, followed the message itself.
181181
b[0] = uint8(copy(b[1:], m))

src/go/ast/ast.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func (g *CommentGroup) Text() string {
134134
}
135135

136136
// Split on newlines.
137-
cl := strings.Split(c, "\n")
137+
cl := strings.SplitSeq(c, "\n")
138138

139139
// Walk lines, stripping trailing white space and adding to list.
140-
for _, l := range cl {
140+
for l := range cl {
141141
lines = append(lines, stripTrailingWhitespace(l))
142142
}
143143
}

src/log/slog/slogtest_test.go

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

4444
func parseLines(src []byte, parse func([]byte) (map[string]any, error)) ([]map[string]any, error) {
4545
var records []map[string]any
46-
for _, line := range bytes.Split(src, []byte{'\n'}) {
46+
for line := range bytes.SplitSeq(src, []byte{'\n'}) {
4747
if len(line) == 0 {
4848
continue
4949
}

0 commit comments

Comments
 (0)