0
0
Fork 0

reuse memory already allocated for copies of docids

when the term field reader is copying ID values out of the
kv store's iterator, it is already attempting to reuse the
term frequency row data structure.  this change allows us
to also attempt to reuse the []byte allocated for previous
copies of the docid.  we reset the slice length to zero
then copy the data into the existing slice, avoiding
new allocation and garbage collection in the cases where
there is already enough space
This commit is contained in:
Marty Schoch 2016-08-03 13:45:48 -04:00
parent 4b1b866e0f
commit 89d83cb5a1
1 changed files with 4 additions and 2 deletions

View File

@ -83,7 +83,8 @@ func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*
if rv == nil {
rv = &index.TermFieldDoc{}
}
rv.ID = append([]byte(nil), tfr.doc...)
rv.ID = rv.ID[:0]
rv.ID = append(rv.ID, tfr.doc...)
rv.Freq = tfr.freq
rv.Norm = float64(tfr.norm)
if tfr.vectors != nil {
@ -110,7 +111,8 @@ func (r *UpsideDownCouchTermFieldReader) Advance(docID index.IndexInternalID, pr
if rv == nil {
rv = &index.TermFieldDoc{}
}
rv.ID = append([]byte(nil), tfr.doc...)
rv.ID = rv.ID[:0]
rv.ID = append(rv.ID, tfr.doc...)
rv.Freq = tfr.freq
rv.Norm = float64(tfr.norm)
if tfr.vectors != nil {