Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit 8dfa537

Browse files
authored
Re-use 'keys' in ReadOffsetTable (#645)
* Re-use 'keys' in ReadOffsetTable Signed-off-by: Ganesh Vernekar <[email protected]> * Add comment Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent d230c67 commit 8dfa537

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index/index.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,13 @@ func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) e
781781
d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
782782
cnt := d.Be32()
783783

784+
// The Postings offset table takes only 2 keys per entry (name and value of label),
785+
// and the LabelIndices offset table takes only 1 key per entry (a label name).
786+
// Hence setting the size to max of both, i.e. 2.
787+
keys := make([]string, 0, 2)
784788
for d.Err() == nil && d.Len() > 0 && cnt > 0 {
785789
keyCount := d.Uvarint()
786-
keys := make([]string, 0, keyCount)
790+
keys = keys[:0]
787791

788792
for i := 0; i < keyCount; i++ {
789793
keys = append(keys, d.UvarintStr())

0 commit comments

Comments
 (0)