optimization comments on DocumentMatch instance reuse
This commit is contained in:
parent
b744148449
commit
b564ebbfbe
|
@ -60,7 +60,7 @@ func (tksc *TopScoreCollector) Took() time.Duration {
|
||||||
func (tksc *TopScoreCollector) Collect(ctx context.Context, searcher search.Searcher) error {
|
func (tksc *TopScoreCollector) Collect(ctx context.Context, searcher search.Searcher) error {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
var err error
|
var err error
|
||||||
var pre search.DocumentMatch // Pre-alloc'ed instance.
|
var pre search.DocumentMatch // A single pre-alloc'ed, reused instance.
|
||||||
var next *search.DocumentMatch
|
var next *search.DocumentMatch
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -104,6 +104,9 @@ func (tksc *TopScoreCollector) collectSingle(dmIn *search.DocumentMatch) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because the dmIn will be the single, pre-allocated, reused
|
||||||
|
// instance, we need to copy the dmIn into a new, standalone
|
||||||
|
// instance before inserting into our candidate results list.
|
||||||
dm := &search.DocumentMatch{}
|
dm := &search.DocumentMatch{}
|
||||||
*dm = *dmIn
|
*dm = *dmIn
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user