Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 31e24b6

Browse files
committed
plumbing: format/idxfile, save another 18% of time in genOffsetHash by not using iterator and not loading CRC
Signed-off-by: Filip Navara <[email protected]>
1 parent 3abbe14 commit 31e24b6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

plumbing/format/idxfile/idxfile.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,22 @@ func (idx *MemoryIndex) genOffsetHash() error {
204204
idx.offsetHash = make(map[int64]plumbing.Hash, count)
205205
idx.offsetHashIsFull = true
206206

207-
iter, err := idx.Entries()
208-
if err != nil {
209-
return err
210-
}
211-
212-
for {
213-
entry, err := iter.Next()
214-
if err != nil {
215-
if err == io.EOF {
216-
return nil
207+
var hash plumbing.Hash
208+
i := uint32(0)
209+
for firstLevel, fanoutValue := range idx.Fanout {
210+
hashPos := idx.FanoutMapping[firstLevel]
211+
for secondLevel := uint32(0); i < fanoutValue; i++ {
212+
copy(hash[:], idx.Names[hashPos][secondLevel*objectIDLength:])
213+
if idx.FanoutMapping[hash[0]] != idx.FanoutMapping[firstLevel] {
214+
panic(firstLevel)
217215
}
218-
return err
216+
offset := int64(idx.getOffset(idx.FanoutMapping[hash[0]], int(secondLevel)))
217+
idx.offsetHash[offset] = hash
218+
secondLevel++
219219
}
220-
221-
idx.offsetHash[int64(entry.Offset)] = entry.Hash
222220
}
221+
222+
return nil
223223
}
224224

225225
// Count implements the Index interface.

0 commit comments

Comments
 (0)