0
0
Fork 0

scorch optimize docInternalToNumber() to avoid allocations

docInternalToNumber() no longer allocates a reader instance and a
heap uint64 to hold the result.
This commit is contained in:
Steve Yen 2018-03-28 10:01:01 -07:00
parent fd07fdb862
commit b955bdcd72
1 changed files with 3 additions and 5 deletions

View File

@ -413,12 +413,10 @@ func docNumberToBytes(buf []byte, in uint64) []byte {
}
func docInternalToNumber(in index.IndexInternalID) (uint64, error) {
var res uint64
err := binary.Read(bytes.NewReader(in), binary.BigEndian, &res)
if err != nil {
return 0, err
if len(in) != 8 {
return 0, fmt.Errorf("wrong len for IndexInternalID: %q", in)
}
return res, nil
return binary.BigEndian.Uint64(in), nil
}
func (i *IndexSnapshot) DocumentVisitFieldTerms(id index.IndexInternalID,