From: Matthew Dempsky Date: Wed, 7 Jul 2021 19:33:40 +0000 (-0700) Subject: cmd/compile: optimize types.sconv X-Git-Tag: go1.17rc1~6 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b003a8b1ae;p=gostls13.git cmd/compile: optimize types.sconv Now that symfmt is simpler, we can simply manually inline it into sconv. Importantly, this allows us to avoid allocating a buffer + writing a string + re-interning it when we don't need to qualify the identifier. Passes toolstash -cmp. Updates #47087. Change-Id: I47b57aef22301ba242556a645346f478f0c1a7d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/333162 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go index 0ce423dae7..7b284aa661 100644 --- a/src/cmd/compile/internal/types/fmt.go +++ b/src/cmd/compile/internal/types/fmt.go @@ -112,11 +112,19 @@ func sconv(s *Sym, verb rune, mode fmtMode) string { if s.Name == "_" { return "_" } + + q := pkgqual(s.Pkg, verb, mode) + if q == "" { + return s.Name + } + buf := fmtBufferPool.Get().(*bytes.Buffer) buf.Reset() defer fmtBufferPool.Put(buf) - symfmt(buf, s, verb, mode) + buf.WriteString(q) + buf.WriteByte('.') + buf.WriteString(s.Name) return InternString(buf.Bytes()) }