From 7e9f1c7147ab823ed6d274283d8603deb4cabf69 Mon Sep 17 00:00:00 2001 From: XD-DENG Date: Mon, 19 Oct 2020 20:51:51 +0200 Subject: [PATCH] Use strings.Builder for more efficient string concatenation It minimizes memory copying. Reference: https://golang.org/pkg/strings/#Builder --- pkg/cmd/pr/create/create.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 09b2ba1f7..35040e9d4 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -501,11 +501,11 @@ func computeDefaults(baseRef, headRef string) (shared.Defaults, error) { } else { out.Title = utils.Humanize(headRef) - body := "" + var body strings.Builder for i := len(commits) - 1; i >= 0; i-- { - body += fmt.Sprintf("- %s\n", commits[i].Title) + fmt.Fprintf(&body, "- %s\n", commits[i].Title) } - out.Body = body + out.Body = body.String() } return out, nil