]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize types.sconv
authorMatthew Dempsky <mdempsky@google.com>
Wed, 7 Jul 2021 19:33:40 +0000 (12:33 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 7 Jul 2021 22:28:19 +0000 (22:28 +0000)
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>
src/cmd/compile/internal/types/fmt.go

index 0ce423dae70b28e181294efd5ec0463708da34fe..7b284aa661464b952d9fe1ded7bdc17d715d0cb4 100644 (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())
 }