aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-04-26 09:05:07 +0200
committerFilip Navara <filip.navara@gmail.com>2019-04-26 09:05:07 +0200
commit5943b4548d43cd5ed7975e29fa057a4b0cb180cf (patch)
tree8d61b6da88f0367fba8566059edd7349db49219f
parent1f19576e7fe5452e71a352657045b8c801fb50b0 (diff)
downloadgo-git-5943b4548d43cd5ed7975e29fa057a4b0cb180cf.tar.gz
plumbing: format/idxfile, avoid looking up the fanout mapping in the iterator twice
Signed-off-by: Filip Navara <filip.navara@gmail.com>
-rw-r--r--plumbing/format/idxfile/idxfile.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/plumbing/format/idxfile/idxfile.go b/plumbing/format/idxfile/idxfile.go
index b5e71f0..14b5860 100644
--- a/plumbing/format/idxfile/idxfile.go
+++ b/plumbing/format/idxfile/idxfile.go
@@ -207,10 +207,10 @@ func (idx *MemoryIndex) genOffsetHash() error {
var hash plumbing.Hash
i := uint32(0)
for firstLevel, fanoutValue := range idx.Fanout {
- pos := idx.FanoutMapping[firstLevel]
+ mappedFirstLevel := idx.FanoutMapping[firstLevel]
for secondLevel := uint32(0); i < fanoutValue; i++ {
- copy(hash[:], idx.Names[pos][secondLevel*objectIDLength:])
- offset := int64(idx.getOffset(pos, int(secondLevel)))
+ copy(hash[:], idx.Names[mappedFirstLevel][secondLevel*objectIDLength:])
+ offset := int64(idx.getOffset(mappedFirstLevel, int(secondLevel)))
idx.offsetHash[offset] = hash
secondLevel++
}
@@ -285,14 +285,11 @@ func (i *idxfileEntryIter) Next() (*Entry, error) {
continue
}
+ mappedFirstLevel := i.idx.FanoutMapping[i.firstLevel]
entry := new(Entry)
- ofs := i.secondLevel * objectIDLength
- copy(entry.Hash[:], i.idx.Names[i.idx.FanoutMapping[i.firstLevel]][ofs:])
-
- pos := i.idx.FanoutMapping[entry.Hash[0]]
-
- entry.Offset = i.idx.getOffset(pos, i.secondLevel)
- entry.CRC32 = i.idx.getCRC32(pos, i.secondLevel)
+ copy(entry.Hash[:], i.idx.Names[mappedFirstLevel][i.secondLevel*objectIDLength:])
+ entry.Offset = i.idx.getOffset(mappedFirstLevel, i.secondLevel)
+ entry.CRC32 = i.idx.getCRC32(mappedFirstLevel, i.secondLevel)
i.secondLevel++
i.total++