0
0
Fork 0

optimize upside-down DictionaryRow for fewer parsing alloc's

This commit is contained in:
Steve Yen 2016-10-11 08:32:30 -07:00
parent 2d72b542c0
commit 01fb59d293
4 changed files with 12 additions and 27 deletions

View File

@ -78,11 +78,11 @@ func toLowerDeferredCopy(s []byte) []byte {
// Handles the Unicode edge-case where the last
// rune in a word on the greek Σ needs to be converted
// differently.
if l == 'σ' && i + 2 == len(s) {
if l == 'σ' && i+2 == len(s) {
l = 'ς'
}
lwid := utf8.RuneLen(l)
lwid := utf8.RuneLen(l)
if lwid > wid {
// utf-8 encoded replacement is wider
// for now, punt and defer

View File

@ -44,7 +44,7 @@ func newUpsideDownCouchFieldDict(indexReader *IndexReader, field uint16, startTe
return &UpsideDownCouchFieldDict{
indexReader: indexReader,
iterator: it,
dictRow: &DictionaryRow{}, // Pre-alloced, reused row.
dictRow: &DictionaryRow{}, // Pre-alloced, reused row.
dictEntry: &index.DictEntry{}, // Pre-alloced, reused entry.
field: field,
}, nil

View File

@ -242,9 +242,9 @@ func NewFieldRowKV(key, value []byte) (*FieldRow, error) {
const DictionaryRowMaxValueSize = binary.MaxVarintLen64
type DictionaryRow struct {
field uint16
term []byte
count uint64
field uint16
}
func (dr *DictionaryRow) Key() []byte {
@ -315,35 +315,20 @@ func NewDictionaryRowK(key []byte) (*DictionaryRow, error) {
}
func (dr *DictionaryRow) parseDictionaryK(key []byte) error {
buf := bytes.NewBuffer(key)
_, err := buf.ReadByte() // type
if err != nil {
return err
dr.field = binary.LittleEndian.Uint16(key[1:3])
if dr.term != nil {
dr.term = dr.term[:0]
}
err = binary.Read(buf, binary.LittleEndian, &dr.field)
if err != nil {
return err
}
dr.term, err = buf.ReadBytes(ByteSeparator)
// there is no separator expected here, should get EOF
if err != io.EOF {
return err
}
dr.term = append(dr.term, key[3:]...)
return nil
}
func (dr *DictionaryRow) parseDictionaryV(value []byte) error {
buf := bytes.NewBuffer(value)
count, err := binary.ReadUvarint(buf)
if err != nil {
return err
count, nread := binary.Uvarint(value)
if nread <= 0 {
return fmt.Errorf("DictionaryRow parse Uvarint error, nread: %d", nread)
}
dr.count = count
return nil
}

View File

@ -127,7 +127,7 @@ func (s *DisjunctionSearcher) updateMatches() error {
return err
}
last := len(s.searchers)-1
last := len(s.searchers) - 1
s.searchers[i] = s.searchers[last]
s.searchers = s.searchers[0:last]
s.currs[i] = s.currs[last]