cmd/go: use strings.Builder

Change-Id: I0db93b7bdcd622ce9e23df183de4737744e6d6ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/428294
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
This commit is contained in:
cuiweixie 2022-09-04 20:36:49 +08:00 committed by Gopher Robot
parent 7722b3c86d
commit 501df45199
7 changed files with 8 additions and 11 deletions

View File

@ -1421,7 +1421,7 @@ func TestLdFlagsLongArgumentsIssue42295(t *testing.T) {
print(extern)
}`)
testStr := "test test test test test \n\\ "
var buf bytes.Buffer
var buf strings.Builder
for buf.Len() < sys.ExecArgLengthLimit+1 {
buf.WriteString(testStr)
}

View File

@ -45,7 +45,7 @@ func runBug(ctx context.Context, cmd *base.Command, args []string) {
}
work.BuildInit()
var buf bytes.Buffer
var buf strings.Builder
buf.WriteString(bugHeader)
printGoVersion(&buf)
buf.WriteString("### Does this issue reproduce with the latest release?\n\n\n")

View File

@ -7,7 +7,6 @@ package help
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
@ -31,7 +30,7 @@ func Help(w io.Writer, args []string) {
fmt.Fprintln(w, "// Code generated by mkalldocs.sh; DO NOT EDIT.")
fmt.Fprintln(w, "// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.")
fmt.Fprintln(w)
buf := new(bytes.Buffer)
buf := new(strings.Builder)
PrintUsage(buf, base.Go)
usage := &base.Command{Long: buf.String()}
cmds := []*base.Command{usage}

View File

@ -94,7 +94,6 @@ package modload
// if those packages are not found in existing dependencies of the main module.
import (
"bytes"
"context"
"errors"
"fmt"
@ -2152,7 +2151,7 @@ func (pkg *loadPkg) stackText() string {
stack = append(stack, p)
}
var buf bytes.Buffer
var buf strings.Builder
for i := len(stack) - 1; i >= 0; i-- {
p := stack[i]
fmt.Fprint(&buf, p.path)

View File

@ -5,7 +5,6 @@
package work
import (
"bytes"
"fmt"
"io/fs"
"os"
@ -233,7 +232,7 @@ func TestRespectSetgidDir(t *testing.T) {
// Check that `cp` is called instead of `mv` by looking at the output
// of `(*Builder).ShowCmd` afterwards as a sanity check.
cfg.BuildX = true
var cmdBuf bytes.Buffer
var cmdBuf strings.Builder
b.Print = func(a ...any) (int, error) {
return cmdBuf.WriteString(fmt.Sprint(a...))
}

View File

@ -160,12 +160,12 @@ func (b *Builder) toolID(name string) string {
cmdline := str.StringList(cfg.BuildToolexec, path, "-V=full")
cmd := exec.Command(cmdline[0], cmdline[1:]...)
var stdout, stderr bytes.Buffer
var stdout, stderr strings.Builder
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
if stderr.Len() > 0 {
os.Stderr.Write(stderr.Bytes())
os.Stderr.WriteString(stderr.String())
}
base.Fatalf("go: error obtaining buildID for %s: %v", desc, err)
}

View File

@ -2159,7 +2159,7 @@ func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...any) ([
// output unambiguous.
// TODO: See issue 5279. The printing of commands needs a complete redo.
func joinUnambiguously(a []string) string {
var buf bytes.Buffer
var buf strings.Builder
for i, s := range a {
if i > 0 {
buf.WriteByte(' ')