Przeglądaj źródła

refactor: replace Split in loops with more efficient SplitSeq

Signed-off-by: vicerace <[email protected]>
vicerace 1 miesiąc temu
rodzic
commit
822f5a702b

+ 1 - 1
cmd/compose/top_test.go

@@ -321,7 +321,7 @@ func TestRunTopCore(t *testing.T) {
 
 func trim(s string) string {
 	var out bytes.Buffer
-	for _, line := range strings.Split(strings.TrimSpace(s), "\n") {
+	for line := range strings.SplitSeq(strings.TrimSpace(s), "\n") {
 		out.WriteString(strings.TrimSpace(line))
 		out.WriteRune('\n')
 	}

+ 1 - 1
cmd/formatter/logs.go

@@ -119,7 +119,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
 	}
 	p := l.getPresenter(container)
 	timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
-	for _, line := range strings.Split(message, "\n") {
+	for line := range strings.SplitSeq(message, "\n") {
 		if l.timestamp {
 			_, _ = fmt.Fprintf(w, "%s%s %s\n", p.prefix, timestamp, line)
 		} else {

+ 1 - 1
pkg/compose/compose.go

@@ -386,7 +386,7 @@ func (s *composeService) projectFromName(containers Containers, projectName stri
 		dependencies := service.Labels[api.DependenciesLabel]
 		if dependencies != "" {
 			service.DependsOn = types.DependsOnConfig{}
-			for _, dc := range strings.Split(dependencies, ",") {
+			for dc := range strings.SplitSeq(dependencies, ",") {
 				dcArr := strings.Split(dc, ":")
 				condition := ServiceConditionRunningOrHealthy
 				// Let's restart the dependency by default if we don't have the info stored in the label

+ 1 - 1
pkg/compose/ls.go

@@ -73,7 +73,7 @@ func combinedConfigFiles(containers []container.Summary) (string, error) {
 			return "", fmt.Errorf("no label %q set on container %q of compose project", api.ConfigFilesLabel, c.ID)
 		}
 
-		for _, f := range strings.Split(files, ",") {
+		for f := range strings.SplitSeq(files, ",") {
 			if !slices.Contains(configFiles, f) {
 				configFiles = append(configFiles, f)
 			}

+ 2 - 2
pkg/e2e/scale_test.go

@@ -169,8 +169,8 @@ func TestScaleDownRemovesObsolete(t *testing.T) {
 
 func checkServiceContainer(t *testing.T, stdout, containerName, containerState string, count int) {
 	found := 0
-	lines := strings.Split(stdout, "\n")
-	for _, line := range lines {
+	lines := strings.SplitSeq(stdout, "\n")
+	for line := range lines {
 		if strings.Contains(line, containerName) && strings.Contains(line, containerState) {
 			found++
 		}