From bd73d1bb75eb3c7bf3c2cb8c96b4d60efa41ac7a Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Fri, 31 Mar 2017 10:22:17 -0700 Subject: [PATCH] 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. --- search/collector/heap.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/search/collector/heap.go b/search/collector/heap.go index 19f3a059..f18993a8 100644 --- a/search/collector/heap.go +++ b/search/collector/heap.go @@ -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