Re-use 'keys' in ReadOffsetTable (#645)

* Re-use 'keys' in ReadOffsetTable

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>

* Add comment

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
Ganesh Vernekar 2019-07-09 15:16:42 +05:30 committed by GitHub
parent d230c67aa1
commit 8dfa537843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -781,9 +781,13 @@ func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) e
d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
cnt := d.Be32()
// The Postings offset table takes only 2 keys per entry (name and value of label),
// and the LabelIndices offset table takes only 1 key per entry (a label name).
// Hence setting the size to max of both, i.e. 2.
keys := make([]string, 0, 2)
for d.Err() == nil && d.Len() > 0 && cnt > 0 {
keyCount := d.Uvarint()
keys := make([]string, 0, keyCount)
keys = keys[:0]
for i := 0; i < keyCount; i++ {
keys = append(keys, d.UvarintStr())