updated attempt to reuse []byte
previous attempt was flawed (but maked by Reset() method) new approach is to do this work in the Reset() method itself, logically this is where it belongs. but further we acknowledge that IndexInternalID []byte lifetime lives beyond the TermFieldDoc, so another copy is made into the DocumentMatch. Although this introduces yet another copy the theory being tested is that it allows each of these structuress to reuse memory without additional allocation.
This commit is contained in:
parent
89d83cb5a1
commit
d7405a4d79
|
@ -123,7 +123,9 @@ type TermFieldDoc struct {
|
|||
}
|
||||
|
||||
func (tfd *TermFieldDoc) Reset() *TermFieldDoc {
|
||||
id := tfd.ID
|
||||
*tfd = TermFieldDoc{}
|
||||
tfd.ID = id[:0]
|
||||
return tfd
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,6 @@ func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*
|
|||
if rv == nil {
|
||||
rv = &index.TermFieldDoc{}
|
||||
}
|
||||
rv.ID = rv.ID[:0]
|
||||
rv.ID = append(rv.ID, tfr.doc...)
|
||||
rv.Freq = tfr.freq
|
||||
rv.Norm = float64(tfr.norm)
|
||||
|
@ -111,7 +110,6 @@ func (r *UpsideDownCouchTermFieldReader) Advance(docID index.IndexInternalID, pr
|
|||
if rv == nil {
|
||||
rv = &index.TermFieldDoc{}
|
||||
}
|
||||
rv.ID = rv.ID[:0]
|
||||
rv.ID = append(rv.ID, tfr.doc...)
|
||||
rv.Freq = tfr.freq
|
||||
rv.Norm = float64(tfr.norm)
|
||||
|
|
|
@ -132,7 +132,7 @@ func (s *TermQueryScorer) Score(termMatch *index.TermFieldDoc, preAllocated *sea
|
|||
if rv == nil {
|
||||
rv = &search.DocumentMatch{}
|
||||
}
|
||||
rv.IndexInternalID = termMatch.ID
|
||||
rv.IndexInternalID = append(rv.IndexInternalID, termMatch.ID...)
|
||||
rv.Score = score
|
||||
if s.explain {
|
||||
rv.Expl = scoreExplanation
|
||||
|
|
|
@ -89,7 +89,9 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
|
|||
}
|
||||
|
||||
func (dm *DocumentMatch) Reset() *DocumentMatch {
|
||||
indexInternalId := dm.IndexInternalID
|
||||
*dm = DocumentMatch{}
|
||||
dm.IndexInternalID = indexInternalId[:0]
|
||||
return dm
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue