mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/internal/goobj2, cmd/link: avoid some repeated offset calculations
When iterating relocations, do the offset calculation just once. This gives some speedup: (linking cmd/compile) Deadcode 52.8ms ± 1% 47.6ms ± 1% -10.01% (p=0.008 n=5+5) Dostkcheck 44.2ms ± 1% 41.0ms ± 1% -7.29% (p=0.008 n=5+5) Change-Id: I09e38bc29afc379a81f99e3ee4ff467bc1b5f8a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/222302 Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
3277db4ccf
commit
8e100a05a5
3 changed files with 21 additions and 5 deletions
|
|
@ -31,7 +31,9 @@ type Sym int
|
|||
// Relocs encapsulates the set of relocations on a given symbol; an
|
||||
// instance of this type is returned by the Loader Relocs() method.
|
||||
type Relocs struct {
|
||||
Count int // number of relocs
|
||||
Count int // == len(rs), TODO: remove
|
||||
|
||||
rs []goobj2.Reloc2
|
||||
|
||||
li int // local index of symbol whose relocs we're examining
|
||||
r *oReader // object reader for containing package
|
||||
|
|
@ -1469,11 +1471,13 @@ func (relocs *Relocs) At2(j int) Reloc2 {
|
|||
// XXX populate a goobj2.Reloc from external reloc record.
|
||||
// Ugly. Maybe we just want to use this format to store the
|
||||
// reloc record in the first place?
|
||||
// Also there is more speedup if we could remove the
|
||||
// conditional here.
|
||||
var b goobj2.Reloc2
|
||||
b.Set(r.Off, r.Size, 0, r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)})
|
||||
return Reloc2{&b, relocs.r, relocs.l, r.Type}
|
||||
}
|
||||
return Reloc2{relocs.r.Reloc2(relocs.li, j), relocs.r, relocs.l, 0}
|
||||
return Reloc2{&relocs.rs[j], relocs.r, relocs.l, 0}
|
||||
}
|
||||
|
||||
// ReadAll method reads all relocations for a symbol into the
|
||||
|
|
@ -1539,14 +1543,17 @@ func (l *Loader) Relocs(i Sym) Relocs {
|
|||
// Relocs returns a Relocs object given a local sym index and reader.
|
||||
func (l *Loader) relocs(r *oReader, li int) Relocs {
|
||||
var n int
|
||||
var rs []goobj2.Reloc2
|
||||
if l.isExtReader(r) {
|
||||
pp := l.payloads[li]
|
||||
n = len(pp.relocs)
|
||||
} else {
|
||||
n = r.NReloc(li)
|
||||
rs = r.Relocs2(li)
|
||||
n = len(rs)
|
||||
}
|
||||
return Relocs{
|
||||
Count: n,
|
||||
rs: rs,
|
||||
li: li,
|
||||
r: r,
|
||||
l: l,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue