File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,20 @@ func NewIndexFromIdxFile(idxf *idxfile.Idxfile) *Index {
31
31
byHash : make (map [plumbing.Hash ]* idxfile.Entry , idxf .ObjectCount ),
32
32
byOffset : make ([]* idxfile.Entry , 0 , idxf .ObjectCount ),
33
33
}
34
- for _ , e := range idxf .Entries {
34
+ sorted := true
35
+ for i , e := range idxf .Entries {
35
36
idx .addUnsorted (e )
37
+ if i > 0 && idx .byOffset [i - 1 ].Offset >= e .Offset {
38
+ sorted = false
39
+ }
40
+ }
41
+
42
+ // If the idxfile was loaded from a regular packfile index
43
+ // then it will already be in offset order, in which case we
44
+ // can avoid doing a relatively expensive idempotent sort.
45
+ if ! sorted {
46
+ sort .Sort (orderByOffset (idx .byOffset ))
36
47
}
37
- sort .Sort (orderByOffset (idx .byOffset ))
38
48
39
49
return idx
40
50
}
You can’t perform that action at this time.
0 commit comments