| @@ -57,7 +57,7 @@ impl index::File { · 56 unmodified lines |
| 57 | | 57 | |
| 58 | /// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes. | 58 | /// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes. |
| 59 | /// The index ranges from 0 to self.num_objects() | 59 | /// The index ranges from 0 to self.num_objects() |
| 60 | pub fn oid_at_index(&self, index: u32) -> &[u8] { | 60 | pub fn oid_at_index(&self, index: u32) -> &[u8; 20] { |
| 61 | let index: usize = index | 61 | let index: usize = index |
| 62 | .try_into() | 62 | .try_into() |
| 63 | .expect("an architecture able to hold 32 bits of integer"); | 63 | .expect("an architecture able to hold 32 bits of integer"); |
| @@ -65,7 +65,9 @@ impl index::File { · 1 unmodified line |
| 65 | index::Kind::V2 => V2_HEADER_SIZE + index * SHA1_SIZE, | 65 | index::Kind::V2 => V2_HEADER_SIZE + index * SHA1_SIZE, |
| 66 | index::Kind::V1 => V1_HEADER_SIZE + index * (N32_SIZE + SHA1_SIZE) + N32_SIZE, | 66 | index::Kind::V1 => V1_HEADER_SIZE + index * (N32_SIZE + SHA1_SIZE) + N32_SIZE, |
| 67 | }; | 67 | }; |
| 68 | &self.data[start..start + SHA1_SIZE] | 68 | (&self.data[start..start + SHA1_SIZE]) |
| | 69 | .try_into() |
| | 70 | .expect("20 bytes exactly") |
| 69 | } | 71 | } |
| 70 | | 72 | |
| 71 | pub fn pack_offset_at_index(&self, index: u32) -> u64 { | 73 | pub fn pack_offset_at_index(&self, index: u32) -> u64 { |
| @@ -98,7 +100,7 @@ impl index::File { · 26 unmodified lines |
| 98 | } | 100 | } |
| 99 | | 101 | |
| 100 | /// Returns the offset of the given object ID (20 bytes) for use with the `(oid|pack_offset|crc32)_at_index()` | 102 | /// Returns the offset of the given object ID (20 bytes) for use with the `(oid|pack_offset|crc32)_at_index()` |
| 101 | pub fn lookup_index(&self, id: &[u8]) -> Option<u32> { | 103 | pub fn lookup_index(&self, id: &[u8; 20]) -> Option<u32> { |
| 102 | let first_byte = id[0] as usize; | 104 | let first_byte = id[0] as usize; |
| 103 | let mut upper_bound = self.fan[first_byte]; | 105 | let mut upper_bound = self.fan[first_byte]; |
| 104 | let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 }; | 106 | let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 }; |