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:
parent
78a7ae562f
commit
03c8b2b7ec
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue