From 866fbb67d0285240c3cf0c430ff018d20f99379c Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sun, 4 Sep 2022 20:05:52 +0800 Subject: [PATCH] cmd/dist: use strings.Builder Change-Id: I56bd5d6b1333a96339340e5af5e6470cc7fb11a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/428287 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/cmd/dist/buildgo.go | 11 +++++------ src/cmd/dist/buildruntime.go | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cmd/dist/buildgo.go b/src/cmd/dist/buildgo.go index 520dde7050..29b0167f47 100644 --- a/src/cmd/dist/buildgo.go +++ b/src/cmd/dist/buildgo.go @@ -5,7 +5,6 @@ package main import ( - "bytes" "fmt" "os" "path/filepath" @@ -28,7 +27,7 @@ import ( // but we also write cmd/cgo/zdefaultcc.go func mkzdefaultcc(dir, file string) { if strings.Contains(file, filepath.FromSlash("go/internal/cfg")) { - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package cfg\n") @@ -40,7 +39,7 @@ func mkzdefaultcc(dir, file string) { return } - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package main\n") @@ -52,7 +51,7 @@ func mkzdefaultcc(dir, file string) { } func defaultCCFunc(name string, defaultcc map[string]string) string { - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "func %s(goos, goarch string) string {\n", name) fmt.Fprintf(&buf, "\tswitch goos+`/`+goarch {\n") @@ -82,7 +81,7 @@ func mkzosarch(dir, file string) { } sort.Strings(list) - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n\n") fmt.Fprintf(&buf, "package cfg\n\n") fmt.Fprintf(&buf, "var OSArchSupportsCgo = map[string]bool{\n") @@ -110,7 +109,7 @@ func mkzcgo(dir, file string) { } sort.Strings(list) - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package build\n") diff --git a/src/cmd/dist/buildruntime.go b/src/cmd/dist/buildruntime.go index 6d88046566..932c509fa4 100644 --- a/src/cmd/dist/buildruntime.go +++ b/src/cmd/dist/buildruntime.go @@ -5,8 +5,8 @@ package main import ( - "bytes" "fmt" + "strings" ) /* @@ -19,7 +19,7 @@ import ( // // (Nothing right now!) func mkzversion(dir, file string) { - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package sys\n") @@ -46,7 +46,7 @@ func mkzversion(dir, file string) { // This is more useful than having it default to generating objects for the // original target (in this example, a Mac). func mkbuildcfg(file string) { - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package buildcfg\n") @@ -75,7 +75,7 @@ func mkbuildcfg(file string) { // // (Nothing right now!) func mkobjabi(file string) { - var buf bytes.Buffer + var buf strings.Builder fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") fmt.Fprintln(&buf) fmt.Fprintf(&buf, "package objabi\n")