From 9a2ede8b01e7190bdaae1eed02f335aba6a2e742 Mon Sep 17 00:00:00 2001 From: Li Yi Date: Tue, 9 Oct 2018 10:33:27 +0800 Subject: [PATCH] Using strings.Builder instead of string appending Signed-off-by: Li Yi (cherry picked from commit 814ced4b30d0d2164c74d2f2007603ce81d0d17b) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/prune.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/command/image/prune.go b/cli/command/image/prune.go index ada47df3bb..0c79d6699c 100644 --- a/cli/command/image/prune.go +++ b/cli/command/image/prune.go @@ -3,6 +3,7 @@ package image import ( "context" "fmt" + "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -73,14 +74,20 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6 } if len(report.ImagesDeleted) > 0 { - output = "Deleted Images:\n" + var sb strings.Builder + sb.WriteString("Deleted Images:\n") for _, st := range report.ImagesDeleted { if st.Untagged != "" { - output += fmt.Sprintln("untagged:", st.Untagged) + sb.WriteString("untagged: ") + sb.WriteString(st.Untagged) + sb.WriteByte('\n') } else { - output += fmt.Sprintln("deleted:", st.Deleted) + sb.WriteString("deleted: ") + sb.WriteString(st.Deleted) + sb.WriteByte('\n') } } + output = sb.String() spaceReclaimed = report.SpaceReclaimed }