@@ -41,12 +41,12 @@ type MemoryIndex struct {
4141 Version uint32
4242 Fanout [256 ]uint32
4343 // FanoutMapping maps the position in the fanout table to the position
44- // in the Names, Offset32 and Crc32 slices. This improves the memory
44+ // in the Names, Offset32 and CRC32 slices. This improves the memory
4545 // usage by not needing an array with unnecessary empty slots.
4646 FanoutMapping [256 ]int
4747 Names [][]byte
4848 Offset32 [][]byte
49- Crc32 [][]byte
49+ CRC32 [][]byte
5050 Offset64 []byte
5151 PackfileChecksum [20 ]byte
5252 IdxChecksum [20 ]byte
@@ -61,20 +61,20 @@ func NewMemoryIndex() *MemoryIndex {
6161 return & MemoryIndex {}
6262}
6363
64- func (idx * MemoryIndex ) findHashIndex (h plumbing.Hash ) int {
64+ func (idx * MemoryIndex ) findHashIndex (h plumbing.Hash ) ( int , bool ) {
6565 k := idx .FanoutMapping [h [0 ]]
6666 if k == noMapping {
67- return - 1
67+ return 0 , false
6868 }
6969
7070 if len (idx .Names ) <= k {
71- return - 1
71+ return 0 , false
7272 }
7373
7474 data := idx .Names [k ]
7575 high := uint64 (len (idx .Offset32 [k ])) >> 2
7676 if high == 0 {
77- return - 1
77+ return 0 , false
7878 }
7979
8080 low := uint64 (0 )
@@ -86,7 +86,7 @@ func (idx *MemoryIndex) findHashIndex(h plumbing.Hash) int {
8686 if cmp < 0 {
8787 high = mid
8888 } else if cmp == 0 {
89- return int (mid )
89+ return int (mid ), true
9090 } else {
9191 low = mid + 1
9292 }
@@ -96,13 +96,13 @@ func (idx *MemoryIndex) findHashIndex(h plumbing.Hash) int {
9696 }
9797 }
9898
99- return - 1
99+ return 0 , false
100100}
101101
102102// Contains implements the Index interface.
103103func (idx * MemoryIndex ) Contains (h plumbing.Hash ) (bool , error ) {
104- i := idx .findHashIndex (h )
105- return i >= 0 , nil
104+ _ , ok := idx .findHashIndex (h )
105+ return ok , nil
106106}
107107
108108// FindOffset implements the Index interface.
@@ -112,8 +112,8 @@ func (idx *MemoryIndex) FindOffset(h plumbing.Hash) (int64, error) {
112112 }
113113
114114 k := idx .FanoutMapping [h [0 ]]
115- i := idx .findHashIndex (h )
116- if i < 0 {
115+ i , ok := idx .findHashIndex (h )
116+ if ! ok {
117117 return 0 , plumbing .ErrObjectNotFound
118118 }
119119
@@ -147,17 +147,17 @@ func (idx *MemoryIndex) getOffset(firstLevel, secondLevel int) (int64, error) {
147147// FindCRC32 implements the Index interface.
148148func (idx * MemoryIndex ) FindCRC32 (h plumbing.Hash ) (uint32 , error ) {
149149 k := idx .FanoutMapping [h [0 ]]
150- i := idx .findHashIndex (h )
151- if i < 0 {
150+ i , ok := idx .findHashIndex (h )
151+ if ! ok {
152152 return 0 , plumbing .ErrObjectNotFound
153153 }
154154
155- return idx .getCrc32 (k , i )
155+ return idx .getCRC32 (k , i )
156156}
157157
158- func (idx * MemoryIndex ) getCrc32 (firstLevel , secondLevel int ) (uint32 , error ) {
158+ func (idx * MemoryIndex ) getCRC32 (firstLevel , secondLevel int ) (uint32 , error ) {
159159 offset := secondLevel << 2
160- buf := bytes .NewBuffer (idx .Crc32 [firstLevel ][offset : offset + 4 ])
160+ buf := bytes .NewBuffer (idx .CRC32 [firstLevel ][offset : offset + 4 ])
161161 return binary .ReadUint32 (buf )
162162}
163163
@@ -253,7 +253,7 @@ func (i *idxfileEntryIter) Next() (*Entry, error) {
253253 }
254254 entry .Offset = uint64 (offset )
255255
256- entry .CRC32 , err = i .idx .getCrc32 (pos , i .secondLevel )
256+ entry .CRC32 , err = i .idx .getCRC32 (pos , i .secondLevel )
257257 if err != nil {
258258 return nil , err
259259 }
0 commit comments