mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: remove allocation in decoding type name
The type name symbol is always from a Go object file and we never change it. Convert the data to string using unsafe conversion without allocation. Linking cmd/go (on macOS/amd64), name old alloc/op new alloc/op delta Deadcode_GC 1.25MB ± 0% 1.17MB ± 0% -6.29% (p=0.000 n=20+20) name old allocs/op new allocs/op delta Deadcode_GC 8.98k ± 0% 0.10k ± 3% -98.91% (p=0.000 n=20+20) Change-Id: I33117ad1f991e4f14ce0b38cceec50b041e3c0a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/490915 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
fa4781a415
commit
630ef2edc2
4 changed files with 27 additions and 4 deletions
|
|
@ -1247,6 +1247,16 @@ func (l *Loader) Data(i Sym) []byte {
|
|||
return r.Data(li)
|
||||
}
|
||||
|
||||
// Returns the symbol content of the i-th symbol as a string. i is global index.
|
||||
func (l *Loader) DataString(i Sym) string {
|
||||
if l.IsExternal(i) {
|
||||
pp := l.getPayload(i)
|
||||
return string(pp.data)
|
||||
}
|
||||
r, li := l.toLocal(i)
|
||||
return r.DataString(li)
|
||||
}
|
||||
|
||||
// FreeData clears the symbol data of an external symbol, allowing the memory
|
||||
// to be freed earlier. No-op for non-external symbols.
|
||||
// i is global index.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue