1
0
mirror of https://github.com/golang/go synced 2024-11-22 18:24:48 -07:00

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 <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2021-07-07 12:33:40 -07:00
parent 11f5df2d67
commit b003a8b1ae

View File

@ -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())
}