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

Commit

Permalink
Merge pull request #869 from dsymonds/compact
Browse files Browse the repository at this point in the history
packfile: optimise NewIndexFromIdxFile for a very common case
  • Loading branch information
mcuadros committed Jun 21, 2018
2 parents 0710c6c + 2d9816a commit b11eaab
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plumbing/format/packfile/index.go
Expand Up @@ -31,10 +31,20 @@ func NewIndexFromIdxFile(idxf *idxfile.Idxfile) *Index {
byHash: make(map[plumbing.Hash]*idxfile.Entry, idxf.ObjectCount),
byOffset: make([]*idxfile.Entry, 0, idxf.ObjectCount),
}
for _, e := range idxf.Entries {
sorted := true
for i, e := range idxf.Entries {
idx.addUnsorted(e)
if i > 0 && idx.byOffset[i-1].Offset >= e.Offset {
sorted = false
}
}

// If the idxfile was loaded from a regular packfile index
// then it will already be in offset order, in which case we
// can avoid doing a relatively expensive idempotent sort.
if !sorted {
sort.Sort(orderByOffset(idx.byOffset))
}
sort.Sort(orderByOffset(idx.byOffset))

return idx
}
Expand Down

0 comments on commit b11eaab

Please sign in to comment.