0
0

Merge pull request #244 from kevgs/master

reducing allocation count
This commit is contained in:
Marty Schoch 2015-10-16 15:51:30 -04:00
commit c9471d5739

View File

@ -402,10 +402,10 @@ func encodeFieldType(f document.Field) byte {
func (udc *UpsideDownCouch) indexField(docID string, field document.Field, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies) ([]index.IndexRow, []*BackIndexTermEntry) { func (udc *UpsideDownCouch) indexField(docID string, field document.Field, fieldIndex uint16, fieldLength int, tokenFreqs analysis.TokenFrequencies) ([]index.IndexRow, []*BackIndexTermEntry) {
rows := make([]index.IndexRow, 0, 100) rows := make([]index.IndexRow, 0, 100)
backIndexTermEntries := make([]*BackIndexTermEntry, 0) backIndexTermEntries := make([]*BackIndexTermEntry, 0, len(tokenFreqs))
fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength))) fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength)))
for _, tf := range tokenFreqs { for k, tf := range tokenFreqs {
var termFreqRow *TermFrequencyRow var termFreqRow *TermFrequencyRow
if field.Options().IncludeTermVectors() { if field.Options().IncludeTermVectors() {
tv, newFieldRows := udc.termVectorsFromTokenFreq(fieldIndex, tf) tv, newFieldRows := udc.termVectorsFromTokenFreq(fieldIndex, tf)
@ -416,7 +416,7 @@ func (udc *UpsideDownCouch) indexField(docID string, field document.Field, field
} }
// record the back index entry // record the back index entry
backIndexTermEntry := BackIndexTermEntry{Term: proto.String(string(tf.Term)), Field: proto.Uint32(uint32(fieldIndex))} backIndexTermEntry := BackIndexTermEntry{Term: proto.String(k), Field: proto.Uint32(uint32(fieldIndex))}
backIndexTermEntries = append(backIndexTermEntries, &backIndexTermEntry) backIndexTermEntries = append(backIndexTermEntries, &backIndexTermEntry)
rows = append(rows, termFreqRow) rows = append(rows, termFreqRow)