aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/pkgpath
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-09-01 21:53:22 +0800
committerMatthew Dempsky <mdempsky@google.com>2022-09-01 21:27:01 +0000
commitdced3461eee8297fe2bd666f2c5146d220b2ab5b (patch)
tree2d56ef39df1c488c81f0e1c398963a55dd1bbb95 /src/cmd/internal/pkgpath
parentd31c4bc2de1105d2b77beb6447166fdae7b64e94 (diff)
downloadgo-dced3461eee8297fe2bd666f2c5146d220b2ab5b.tar.xz
cmd/internal/pkgpath: use strings.Builder
Since when go1.17 is now used for bootstraping. Change-Id: I5f763dec1cb152f94ab1c677d3fa26da17abf097 Reviewed-on: https://go-review.googlesource.com/c/go/+/427557 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Run-TryBot: hopehook <hopehook@golangcn.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/cmd/internal/pkgpath')
-rw-r--r--src/cmd/internal/pkgpath/pkgpath.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/cmd/internal/pkgpath/pkgpath.go b/src/cmd/internal/pkgpath/pkgpath.go
index 40a040a81a..e3c76dced4 100644
--- a/src/cmd/internal/pkgpath/pkgpath.go
+++ b/src/cmd/internal/pkgpath/pkgpath.go
@@ -87,13 +87,11 @@ func toSymbolV1(ppath string) string {
// toSymbolV2 converts a package path using the second mangling scheme.
func toSymbolV2(ppath string) string {
- // This has to build at boostrap time, so it has to build
- // with Go 1.4, so we don't use strings.Builder.
- bsl := make([]byte, 0, len(ppath))
+ var bsl strings.Builder
changed := false
for _, c := range ppath {
if ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9') || c == '_' {
- bsl = append(bsl, byte(c))
+ bsl.WriteByte(byte(c))
continue
}
var enc string
@@ -107,13 +105,13 @@ func toSymbolV2(ppath string) string {
default:
enc = fmt.Sprintf("..U%08x", c)
}
- bsl = append(bsl, enc...)
+ bsl.WriteString(enc)
changed = true
}
if !changed {
return ppath
}
- return string(bsl)
+ return bsl.String()
}
// v3UnderscoreCodes maps from a character that supports an underscore
@@ -137,19 +135,18 @@ var v3UnderscoreCodes = map[byte]byte{
// toSymbolV3 converts a package path using the third mangling scheme.
func toSymbolV3(ppath string) string {
- // This has to build at boostrap time, so it has to build
- // with Go 1.4, so we don't use strings.Builder.
- bsl := make([]byte, 0, len(ppath))
+ var bsl strings.Builder
changed := false
for _, c := range ppath {
if ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9') {
- bsl = append(bsl, byte(c))
+ bsl.WriteByte(byte(c))
continue
}
if c < 0x80 {
if u, ok := v3UnderscoreCodes[byte(c)]; ok {
- bsl = append(bsl, '_', u)
+ bsl.WriteByte('_')
+ bsl.WriteByte(u)
changed = true
continue
}
@@ -164,11 +161,11 @@ func toSymbolV3(ppath string) string {
default:
enc = fmt.Sprintf("_U%08x", c)
}
- bsl = append(bsl, enc...)
+ bsl.WriteString(enc)
changed = true
}
if !changed {
return ppath
}
- return string(bsl)
+ return bsl.String()
}