aboutsummaryrefslogtreecommitdiff
path: root/src/internal/pkgbits/decoder.go
diff options
context:
space:
mode:
authorMark Freeman <mark@golang.org>2025-04-28 13:32:14 -0400
committerGopher Robot <gobot@golang.org>2025-05-06 09:59:00 -0700
commit30b2b767d6d902787b90476fd00eee4c9b3a3f15 (patch)
tree4086c977b71fbec557465ef7fe58cbf14259d689 /src/internal/pkgbits/decoder.go
parent68ca584ffaf3f647eda2706500fba5280f2ad19c (diff)
downloadgo-30b2b767d6d902787b90476fd00eee4c9b3a3f15.tar.xz
pkgbits: alias RelocKind with a SectionKind type
I think that SectionKind better conveys the original intent here, and goes nicely with codifying section relative indices. Change-Id: I96a245e67295a5f9f8e462756a14f60eccec6862 Reviewed-on: https://go-review.googlesource.com/c/go/+/668538 Reviewed-by: Mark Freeman <mark@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Mark Freeman <mark@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/internal/pkgbits/decoder.go')
-rw-r--r--src/internal/pkgbits/decoder.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/internal/pkgbits/decoder.go b/src/internal/pkgbits/decoder.go
index 6268ed13fc..9a8a3da240 100644
--- a/src/internal/pkgbits/decoder.go
+++ b/src/internal/pkgbits/decoder.go
@@ -109,7 +109,7 @@ func NewPkgDecoder(pkgPath, input string) PkgDecoder {
}
// NumElems returns the number of elements in section k.
-func (pr *PkgDecoder) NumElems(k RelocKind) int {
+func (pr *PkgDecoder) NumElems(k SectionKind) int {
count := int(pr.elemEndsEnds[k])
if k > 0 {
count -= int(pr.elemEndsEnds[k-1])
@@ -131,7 +131,7 @@ func (pr *PkgDecoder) Fingerprint() [8]byte {
// AbsIdx returns the absolute index for the given (section, index)
// pair.
-func (pr *PkgDecoder) AbsIdx(k RelocKind, idx RelIndex) int {
+func (pr *PkgDecoder) AbsIdx(k SectionKind, idx RelIndex) int {
absIdx := int(idx)
if k > 0 {
absIdx += int(pr.elemEndsEnds[k-1])
@@ -144,7 +144,7 @@ func (pr *PkgDecoder) AbsIdx(k RelocKind, idx RelIndex) int {
// DataIdx returns the raw element bitstream for the given (section,
// index) pair.
-func (pr *PkgDecoder) DataIdx(k RelocKind, idx RelIndex) string {
+func (pr *PkgDecoder) DataIdx(k SectionKind, idx RelIndex) string {
absIdx := pr.AbsIdx(k, idx)
var start uint32
@@ -163,7 +163,7 @@ func (pr *PkgDecoder) StringIdx(idx RelIndex) string {
// NewDecoder returns a Decoder for the given (section, index) pair,
// and decodes the given SyncMarker from the element bitstream.
-func (pr *PkgDecoder) NewDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
+func (pr *PkgDecoder) NewDecoder(k SectionKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.NewDecoderRaw(k, idx)
r.Sync(marker)
return r
@@ -173,7 +173,7 @@ func (pr *PkgDecoder) NewDecoder(k RelocKind, idx RelIndex, marker SyncMarker) D
// and decodes the given SyncMarker from the element bitstream.
// If possible the Decoder should be RetireDecoder'd when it is no longer
// needed, this will avoid heap allocations.
-func (pr *PkgDecoder) TempDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
+func (pr *PkgDecoder) TempDecoder(k SectionKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.TempDecoderRaw(k, idx)
r.Sync(marker)
return r
@@ -187,7 +187,7 @@ func (pr *PkgDecoder) RetireDecoder(d *Decoder) {
// NewDecoderRaw returns a Decoder for the given (section, index) pair.
//
// Most callers should use NewDecoder instead.
-func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx RelIndex) Decoder {
+func (pr *PkgDecoder) NewDecoderRaw(k SectionKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
@@ -199,13 +199,13 @@ func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx RelIndex) Decoder {
r.Relocs = make([]RelocEnt, r.Len())
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
+ r.Relocs[i] = RelocEnt{SectionKind(r.Len()), RelIndex(r.Len())}
}
return r
}
-func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx RelIndex) Decoder {
+func (pr *PkgDecoder) TempDecoderRaw(k SectionKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
@@ -223,7 +223,7 @@ func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx RelIndex) Decoder {
}
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
+ r.Relocs[i] = RelocEnt{SectionKind(r.Len()), RelIndex(r.Len())}
}
return r
@@ -237,7 +237,7 @@ type Decoder struct {
Relocs []RelocEnt
Data strings.Reader
- k RelocKind
+ k SectionKind
Idx RelIndex
}
@@ -292,7 +292,7 @@ func (r *Decoder) rawVarint() int64 {
return x
}
-func (r *Decoder) rawReloc(k RelocKind, idx int) RelIndex {
+func (r *Decoder) rawReloc(k SectionKind, idx int) RelIndex {
e := r.Relocs[idx]
assert(e.Kind == k)
return e.Idx
@@ -401,7 +401,7 @@ func (r *Decoder) Code(mark SyncMarker) int {
// Reloc decodes a relocation of expected section k from the element
// bitstream and returns an index to the referenced element.
-func (r *Decoder) Reloc(k RelocKind) RelIndex {
+func (r *Decoder) Reloc(k SectionKind) RelIndex {
r.Sync(SyncUseReloc)
return r.rawReloc(k, r.Len())
}