[dev.link] cmd/link: use shared reloc slice in writelines method

Move to a shared/reused slice of loader.Reloc's in a couple of places
in the linker's DWARF writelines method, as opposed to allocating a
new slice each time. Small performance improvement.

Change-Id: I06c64cf7ca00162d24d9421f1d6405c8808ebb83
Reviewed-on: https://go-review.googlesource.com/c/go/+/222758
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-03-10 10:08:50 -04:00
parent efbab6dc7d
commit 69d9664f18

View file

@ -1213,11 +1213,12 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) {
// Grab files for inlined functions.
// TODO: With difficulty, this could be moved into the compiler.
rslice := []loader.Reloc{}
for _, s := range unit.Textp2 {
fnSym := loader.Sym(s)
infosym, _, _, _ := d.ldr.GetFuncDwarfAuxSyms(fnSym)
drelocs := d.ldr.Relocs(infosym)
rslice := drelocs.ReadSyms(nil)
rslice = drelocs.ReadSyms(rslice)
for ri := 0; ri < len(rslice); ri++ {
r := &rslice[ri]
if r.Type != objabi.R_DWARFFILEREF {
@ -1307,7 +1308,7 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) {
fnu := d.ldr.MakeSymbolUpdater(fnSym)
relocs := d.ldr.Relocs(fnSym)
rslice := relocs.ReadAll(nil)
rslice = relocs.ReadAll(rslice)
for ri := range rslice {
r := &rslice[ri]