[dev.link] cmd/internal/goobj2: optimize symbol data access

I wish the compiler inlines the DataOff function and CSEs the
base offset calculation. But it didn't happen. Hand optimize it...

(linking cmd/compile)
Dostkcheck    42.0ms ± 0%    36.1ms ± 2%  -14.07%  (p=0.008 n=5+5)

Change-Id: Iacfbc7243a882158a9a090b7400e216536a311b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/222304
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-03-06 12:36:58 -05:00
parent 3382411d93
commit 3277db4ccf

View File

@ -617,12 +617,17 @@ func (r *Reader) DataOff(i int) uint32 {
// DataSize returns the size of the i-th symbol's data.
func (r *Reader) DataSize(i int) int {
return int(r.DataOff(i+1) - r.DataOff(i))
dataIdxOff := r.h.Offsets[BlkDataIdx] + uint32(i*4)
return int(r.uint32At(dataIdxOff+4) - r.uint32At(dataIdxOff))
}
// Data returns the i-th symbol's data.
func (r *Reader) Data(i int) []byte {
return r.BytesAt(r.DataOff(i), r.DataSize(i))
dataIdxOff := r.h.Offsets[BlkDataIdx] + uint32(i*4)
base := r.h.Offsets[BlkData]
off := r.uint32At(dataIdxOff)
end := r.uint32At(dataIdxOff + 4)
return r.BytesAt(base+off, int(end-off))
}
// AuxDataBase returns the base offset of the aux data block.