aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-04-25 17:52:30 +0200
committerFilip Navara <filip.navara@gmail.com>2019-04-25 17:58:04 +0200
commit1f19576e7fe5452e71a352657045b8c801fb50b0 (patch)
treed9fa40b3fb9537f745da9a37bd0afbde4ae07427 /plumbing
parent3abbe1488144825793f8fa0f78846af77448c623 (diff)
downloadgo-git-1f19576e7fe5452e71a352657045b8c801fb50b0.tar.gz
plumbing: format/idxfile, save another 18% of time in genOffsetHash by not using iterator and not loading CRC
Signed-off-by: Filip Navara <filip.navara@gmail.com>
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/idxfile/idxfile.go25
1 files changed, 11 insertions, 14 deletions
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.