0
0

optimmize heap collector Final() for large counts

The previous heap Final() loop would decrement count all the way to 0
when it only has to fill enough of the return slice.
This commit is contained in:
Steve Yen 2017-03-31 10:22:17 -07:00
parent 7dd52a69d2
commit bd73d1bb75

View File

@ -49,17 +49,12 @@ func (c *collectStoreHeap) Final(skip int, fixup collectorFixup) (search.Documen
return make(search.DocumentMatchCollection, 0), nil
}
rv := make(search.DocumentMatchCollection, size)
for count > 0 {
count--
if count >= skip {
size--
doc := heap.Pop(c).(*search.DocumentMatch)
rv[size] = doc
err := fixup(doc)
if err != nil {
return nil, err
}
for i := size - 1; i >= 0; i-- {
doc := heap.Pop(c).(*search.DocumentMatch)
rv[i] = doc
err := fixup(doc)
if err != nil {
return nil, err
}
}
return rv, nil