From b955bdcd72657b268eb6e6a8d530d919557a3ad0 Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Wed, 28 Mar 2018 10:01:01 -0700 Subject: [PATCH] scorch optimize docInternalToNumber() to avoid allocations docInternalToNumber() no longer allocates a reader instance and a heap uint64 to hold the result. --- index/scorch/snapshot_index.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index/scorch/snapshot_index.go b/index/scorch/snapshot_index.go index 251aa9fa..800d250f 100644 --- a/index/scorch/snapshot_index.go +++ b/index/scorch/snapshot_index.go @@ -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,