0
0
Fork 0

scorch mem segment optimizes DictEntry's across Next() calls

This change optimizes the scorch/mem DictionaryIterator by reusing a
DictEntry struct across multiple Next() calls.  This follows the same
optimization trick and Next() semantics as upsidedown's FieldDict
implementation.
This commit is contained in:
Steve Yen 2018-02-07 14:16:58 -08:00
parent 78a7ae562f
commit 03c8b2b7ec
1 changed files with 5 additions and 4 deletions

View File

@ -76,6 +76,8 @@ type DictionaryIterator struct {
prefix string prefix string
end string end string
offset int offset int
dictEntry index.DictEntry // reused across Next()'s
} }
// Next returns the next entry in the dictionary // Next returns the next entry in the dictionary
@ -95,8 +97,7 @@ func (d *DictionaryIterator) Next() (*index.DictEntry, error) {
d.offset++ d.offset++
postingID := d.d.segment.Dicts[d.d.fieldID][next] postingID := d.d.segment.Dicts[d.d.fieldID][next]
return &index.DictEntry{ d.dictEntry.Term = next
Term: next, d.dictEntry.Count = d.d.segment.Postings[postingID-1].GetCardinality()
Count: d.d.segment.Postings[postingID-1].GetCardinality(), return &d.dictEntry, nil
}, nil
} }