Skip to content

Commit b003a8b

Browse files
committed
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>
1 parent 11f5df2 commit b003a8b

File tree

1 file changed

+9
-1
lines changed
  • src/cmd/compile/internal/types

1 file changed

+9
-1
lines changed

src/cmd/compile/internal/types/fmt.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,19 @@ func sconv(s *Sym, verb rune, mode fmtMode) string {
112112
if s.Name == "_" {
113113
return "_"
114114
}
115+
116+
q := pkgqual(s.Pkg, verb, mode)
117+
if q == "" {
118+
return s.Name
119+
}
120+
115121
buf := fmtBufferPool.Get().(*bytes.Buffer)
116122
buf.Reset()
117123
defer fmtBufferPool.Put(buf)
118124

119-
symfmt(buf, s, verb, mode)
125+
buf.WriteString(q)
126+
buf.WriteByte('.')
127+
buf.WriteString(s.Name)
120128
return InternString(buf.Bytes())
121129
}
122130

0 commit comments

Comments
 (0)