From 8dfa5378439220ec498b6ce237105e3a3685b812 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Date: Tue, 9 Jul 2019 15:16:42 +0530 Subject: [PATCH] Re-use 'keys' in ReadOffsetTable (#645) * Re-use 'keys' in ReadOffsetTable Signed-off-by: Ganesh Vernekar * Add comment Signed-off-by: Ganesh Vernekar --- index/index.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index/index.go b/index/index.go index 6b333fa58..c18f77d16 100644 --- a/index/index.go +++ b/index/index.go @@ -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())