aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/goobj
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-05-01 12:54:27 -0400
committerCherry Mui <cherryyz@google.com>2023-05-02 17:29:09 +0000
commit630ef2edc2a7f6138c9eb0ed8eb8216a32ed0339 (patch)
tree6a3e107e2d4332e6a04caae2e722ef166e592814 /src/cmd/internal/goobj
parentfa4781a41502b283b270f7d83e2678152fd01682 (diff)
downloadgo-630ef2edc2a7f6138c9eb0ed8eb8216a32ed0339.tar.xz
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>
Diffstat (limited to 'src/cmd/internal/goobj')
-rw-r--r--src/cmd/internal/goobj/objfile.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/internal/goobj/objfile.go b/src/cmd/internal/goobj/objfile.go
index 64d453abdc..c9d7ca434c 100644
--- a/src/cmd/internal/goobj/objfile.go
+++ b/src/cmd/internal/goobj/objfile.go
@@ -853,6 +853,15 @@ func (r *Reader) Data(i uint32) []byte {
return r.BytesAt(base+off, int(end-off))
}
+// DataString returns the i-th symbol's data as a string.
+func (r *Reader) DataString(i uint32) string {
+ dataIdxOff := r.h.Offsets[BlkDataIdx] + i*4
+ base := r.h.Offsets[BlkData]
+ off := r.uint32At(dataIdxOff)
+ end := r.uint32At(dataIdxOff + 4)
+ return r.StringAt(base+off, end-off)
+}
+
// NRefName returns the number of referenced symbol names.
func (r *Reader) NRefName() int {
return int(r.h.Offsets[BlkRefName+1]-r.h.Offsets[BlkRefName]) / RefNameSize