From a61c3508885422d83ad58b53d2da9776fb60f242 Mon Sep 17 00:00:00 2001 From: Kosov Eugene Date: Mon, 5 Oct 2015 22:57:10 +0300 Subject: [PATCH] reducing allocation count --- index/upside_down/upside_down.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index/upside_down/upside_down.go b/index/upside_down/upside_down.go index d2ad347b..f1b9a718 100644 --- a/index/upside_down/upside_down.go +++ b/index/upside_down/upside_down.go @@ -408,10 +408,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) { rows := make([]index.IndexRow, 0, 100) - backIndexTermEntries := make([]*BackIndexTermEntry, 0) + backIndexTermEntries := make([]*BackIndexTermEntry, 0, len(tokenFreqs)) fieldNorm := float32(1.0 / math.Sqrt(float64(fieldLength))) - for _, tf := range tokenFreqs { + for k, tf := range tokenFreqs { var termFreqRow *TermFrequencyRow if field.Options().IncludeTermVectors() { tv, newFieldRows := udc.termVectorsFromTokenFreq(fieldIndex, tf) @@ -422,7 +422,7 @@ func (udc *UpsideDownCouch) indexField(docID string, field document.Field, field } // 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) rows = append(rows, termFreqRow)