StringIdx adds a string value to the strings section, if not already present, and returns its index.
(s string)
| 107 | // StringIdx adds a string value to the strings section, if not |
| 108 | // already present, and returns its index. |
| 109 | func (pw *PkgEncoder) StringIdx(s string) Index { |
| 110 | if idx, ok := pw.stringsIdx[s]; ok { |
| 111 | assert(pw.elems[RelocString][idx] == s) |
| 112 | return idx |
| 113 | } |
| 114 | |
| 115 | idx := Index(len(pw.elems[RelocString])) |
| 116 | pw.elems[RelocString] = append(pw.elems[RelocString], s) |
| 117 | pw.stringsIdx[s] = idx |
| 118 | return idx |
| 119 | } |
| 120 | |
| 121 | // NewEncoder returns an Encoder for a new element within the given |
| 122 | // section, and encodes the given SyncMarker as the start of the |