diff options
author | Filip Navara <filip.navara@gmail.com> | 2019-04-26 09:05:07 +0200 |
---|---|---|
committer | Filip Navara <filip.navara@gmail.com> | 2019-04-26 09:05:07 +0200 |
commit | 5943b4548d43cd5ed7975e29fa057a4b0cb180cf (patch) | |
tree | 8d61b6da88f0367fba8566059edd7349db49219f /plumbing | |
parent | 1f19576e7fe5452e71a352657045b8c801fb50b0 (diff) | |
download | go-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>
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/idxfile/idxfile.go | 17 |
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++ |