Skip to content

Commit 822f5a7

Browse files
viceracendeloof
authored andcommitted
refactor: replace Split in loops with more efficient SplitSeq
Signed-off-by: vicerace <[email protected]>
1 parent 68bb7a7 commit 822f5a7

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

cmd/compose/top_test.go

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

322322
func trim(s string) string {
323323
var out bytes.Buffer
324-
for _, line := range strings.Split(strings.TrimSpace(s), "\n") {
324+
for line := range strings.SplitSeq(strings.TrimSpace(s), "\n") {
325325
out.WriteString(strings.TrimSpace(line))
326326
out.WriteRune('\n')
327327
}

cmd/formatter/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
119119
}
120120
p := l.getPresenter(container)
121121
timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
122-
for _, line := range strings.Split(message, "\n") {
122+
for line := range strings.SplitSeq(message, "\n") {
123123
if l.timestamp {
124124
_, _ = fmt.Fprintf(w, "%s%s %s\n", p.prefix, timestamp, line)
125125
} else {

pkg/compose/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (s *composeService) projectFromName(containers Containers, projectName stri
386386
dependencies := service.Labels[api.DependenciesLabel]
387387
if dependencies != "" {
388388
service.DependsOn = types.DependsOnConfig{}
389-
for _, dc := range strings.Split(dependencies, ",") {
389+
for dc := range strings.SplitSeq(dependencies, ",") {
390390
dcArr := strings.Split(dc, ":")
391391
condition := ServiceConditionRunningOrHealthy
392392
// Let's restart the dependency by default if we don't have the info stored in the label

pkg/compose/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func combinedConfigFiles(containers []container.Summary) (string, error) {
7373
return "", fmt.Errorf("no label %q set on container %q of compose project", api.ConfigFilesLabel, c.ID)
7474
}
7575

76-
for _, f := range strings.Split(files, ",") {
76+
for f := range strings.SplitSeq(files, ",") {
7777
if !slices.Contains(configFiles, f) {
7878
configFiles = append(configFiles, f)
7979
}

pkg/e2e/scale_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func TestScaleDownRemovesObsolete(t *testing.T) {
169169

170170
func checkServiceContainer(t *testing.T, stdout, containerName, containerState string, count int) {
171171
found := 0
172-
lines := strings.Split(stdout, "\n")
173-
for _, line := range lines {
172+
lines := strings.SplitSeq(stdout, "\n")
173+
for line := range lines {
174174
if strings.Contains(line, containerName) && strings.Contains(line, containerState) {
175175
found++
176176
}

0 commit comments

Comments
 (0)