internal/pkgbits: add Index type

Element indices are very common in the pkgbits API, so introduce a new
defined type to help make that clearer.

Change-Id: I8f9493e2335601c740eb403d1fdcd11183122907
Reviewed-on: https://go-review.googlesource.com/c/go/+/407435
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-05-18 13:26:38 -07:00
parent 8841699160
commit 4e4db1e257
11 changed files with 93 additions and 87 deletions

View file

@ -257,14 +257,14 @@ func writeUnifiedExport(out io.Writer) {
l := linker{
pw: pkgbits.NewPkgEncoder(base.Debug.SyncFrames),
pkgs: make(map[string]int),
decls: make(map[*types.Sym]int),
pkgs: make(map[string]pkgbits.Index),
decls: make(map[*types.Sym]pkgbits.Index),
}
publicRootWriter := l.pw.NewEncoder(pkgbits.RelocMeta, pkgbits.SyncPublic)
assert(publicRootWriter.Idx == pkgbits.PublicRootIdx)
var selfPkgIdx int
var selfPkgIdx pkgbits.Index
{
pr := localPkgReader
@ -294,11 +294,11 @@ func writeUnifiedExport(out io.Writer) {
}
{
var idxs []int
var idxs []pkgbits.Index
for _, idx := range l.decls {
idxs = append(idxs, idx)
}
sort.Ints(idxs)
sort.Slice(idxs, func(i, j int) bool { return idxs[i] < idxs[j] })
w := publicRootWriter