type Encoder struct {
p *PkgEncoder
- Relocs []RelocEnt
- Data bytes.Buffer // accumulated element bitstream data
+ Relocs []RelocEnt
+ RelocMap map[RelocEnt]uint32
+ Data bytes.Buffer // accumulated element bitstream data
encodingRelocHeader bool
}
func (w *Encoder) rawReloc(r RelocKind, idx Index) int {
- // TODO(mdempsky): Use map for lookup; this takes quadratic time.
- for i, rEnt := range w.Relocs {
- if rEnt.Kind == r && rEnt.Idx == idx {
- return i
+ e := RelocEnt{r, idx}
+ if w.RelocMap != nil {
+ if i, ok := w.RelocMap[e]; ok {
+ return int(i)
}
+ } else {
+ w.RelocMap = make(map[RelocEnt]uint32)
}
i := len(w.Relocs)
- w.Relocs = append(w.Relocs, RelocEnt{r, idx})
+ w.RelocMap[e] = uint32(i)
+ w.Relocs = append(w.Relocs, e)
return i
}
package pkgbits
// A RelocKind indicates a particular section within a unified IR export.
-type RelocKind int
+type RelocKind int32
// An Index represents a bitstream element index within a particular
// section.
-type Index int
+type Index int32
// A relocEnt (relocation entry) is an entry in an element's local
// reference table.