From 1f19576e7fe5452e71a352657045b8c801fb50b0 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 25 Apr 2019 17:52:30 +0200 Subject: plumbing: format/idxfile, save another 18% of time in genOffsetHash by not using iterator and not loading CRC Signed-off-by: Filip Navara --- plumbing/format/idxfile/idxfile.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'plumbing/format') diff --git a/plumbing/format/idxfile/idxfile.go b/plumbing/format/idxfile/idxfile.go index 6b77190..b5e71f0 100644 --- a/plumbing/format/idxfile/idxfile.go +++ b/plumbing/format/idxfile/idxfile.go @@ -204,22 +204,19 @@ func (idx *MemoryIndex) genOffsetHash() error { idx.offsetHash = make(map[int64]plumbing.Hash, count) idx.offsetHashIsFull = true - iter, err := idx.Entries() - if err != nil { - return err - } - - for { - entry, err := iter.Next() - if err != nil { - if err == io.EOF { - return nil - } - return err + var hash plumbing.Hash + i := uint32(0) + for firstLevel, fanoutValue := range idx.Fanout { + pos := idx.FanoutMapping[firstLevel] + for secondLevel := uint32(0); i < fanoutValue; i++ { + copy(hash[:], idx.Names[pos][secondLevel*objectIDLength:]) + offset := int64(idx.getOffset(pos, int(secondLevel))) + idx.offsetHash[offset] = hash + secondLevel++ } - - idx.offsetHash[int64(entry.Offset)] = entry.Hash } + + return nil } // Count implements the Index interface. -- cgit