mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <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>
This commit is contained in:
parent
107fcb70de
commit
ca448191c9
3 changed files with 4 additions and 4 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue