Skip to content

Commit 76c02c8

Browse files
committed
refactor: replace Split in loops with more efficient SplitSeq
Signed-off-by: eroderust <eroderust@outlook.com>
1 parent 292b281 commit 76c02c8

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

internal/cmdtest/test_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ type testlogger struct {
225225
}
226226

227227
func (tl *testlogger) Write(b []byte) (n int, err error) {
228-
lines := bytes.Split(b, []byte("\n"))
229-
for _, line := range lines {
228+
lines := bytes.SplitSeq(b, []byte("\n"))
229+
for line := range lines {
230230
if len(line) > 0 {
231231
tl.t.Logf("(stderr) %s", line)
232232
}

log/handler_glog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (h *GlogHandler) Verbosity(level slog.Level) {
8686
// sets V to 3 in all files of any packages whose import path contains "foo"
8787
func (h *GlogHandler) Vmodule(ruleset string) error {
8888
var filter []pattern
89-
for _, rule := range strings.Split(ruleset, ",") {
89+
for rule := range strings.SplitSeq(ruleset, ",") {
9090
// Empty strings such as from a trailing comma can be ignored
9191
if len(rule) == 0 {
9292
continue
@@ -113,7 +113,7 @@ func (h *GlogHandler) Vmodule(ruleset string) error {
113113
}
114114
// Compile the rule pattern into a regular expression
115115
matcher := ".*"
116-
for _, comp := range strings.Split(parts[0], "/") {
116+
for comp := range strings.SplitSeq(parts[0], "/") {
117117
if comp == "*" {
118118
matcher += "(/.*)?"
119119
} else if comp != "" {

p2p/dnsdisc/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func parseBranch(e string) (entry, error) {
366366
return &branchEntry{}, nil // empty entry is OK
367367
}
368368
hashes := make([]string, 0, strings.Count(e, ","))
369-
for _, c := range strings.Split(e, ",") {
369+
for c := range strings.SplitSeq(e, ",") {
370370
if !isValidHash(c) {
371371
return nil, entryError{"branch", errInvalidChild}
372372
}

rlp/internal/rlpstruct/rlpstruct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func parseTag(field Field, lastPublic int) (Tags, error) {
148148
name := field.Name
149149
tag := reflect.StructTag(field.Tag)
150150
var ts Tags
151-
for _, t := range strings.Split(tag.Get("rlp"), ",") {
151+
for t := range strings.SplitSeq(tag.Get("rlp"), ",") {
152152
switch t = strings.TrimSpace(t); t {
153153
case "":
154154
// empty tag is allowed for some reason

rpc/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func runTestScript(t *testing.T, file string) {
9292
defer clientConn.Close()
9393
go server.ServeCodec(NewCodec(serverConn), 0)
9494
readbuf := bufio.NewReader(clientConn)
95-
for _, line := range strings.Split(string(content), "\n") {
95+
for line := range strings.SplitSeq(string(content), "\n") {
9696
line = strings.TrimSpace(line)
9797
switch {
9898
case len(line) == 0 || strings.HasPrefix(line, "//"):

0 commit comments

Comments
 (0)