@@ -31,7 +31,7 @@ impl index::File {
31
31
fn iter_v1 ( & self ) -> impl Iterator < Item = Entry > + ' _ {
32
32
match self . version {
33
33
index:: Version :: V1 => self . data [ V1_HEADER_SIZE ..]
34
- . chunks ( N32_SIZE + self . hash_len )
34
+ . chunks_exact ( N32_SIZE + self . hash_len )
35
35
. take ( self . num_objects as usize )
36
36
. map ( |c| {
37
37
let ( ofs, oid) = c. split_at ( N32_SIZE ) ;
@@ -47,14 +47,19 @@ impl index::File {
47
47
48
48
fn iter_v2 ( & self ) -> impl Iterator < Item = Entry > + ' _ {
49
49
let pack64_offset = self . offset_pack_offset64_v2 ( ) ;
50
+ let oids = self . data [ V2_HEADER_SIZE ..]
51
+ . chunks_exact ( self . hash_len )
52
+ . take ( self . num_objects as usize ) ;
53
+ let crcs = self . data [ self . offset_crc32_v2 ( ) ..]
54
+ . chunks_exact ( N32_SIZE )
55
+ . take ( self . num_objects as usize ) ;
56
+ let offsets = self . data [ self . offset_pack_offset_v2 ( ) ..]
57
+ . chunks_exact ( N32_SIZE )
58
+ . take ( self . num_objects as usize ) ;
59
+ assert_eq ! ( oids. len( ) , crcs. len( ) ) ;
60
+ assert_eq ! ( crcs. len( ) , offsets. len( ) ) ;
50
61
match self . version {
51
- index:: Version :: V2 => izip ! (
52
- self . data[ V2_HEADER_SIZE ..] . chunks( self . hash_len) ,
53
- self . data[ self . offset_crc32_v2( ) ..] . chunks( N32_SIZE ) ,
54
- self . data[ self . offset_pack_offset_v2( ) ..] . chunks( N32_SIZE )
55
- )
56
- . take ( self . num_objects as usize )
57
- . map ( move |( oid, crc32, ofs32) | Entry {
62
+ index:: Version :: V2 => izip ! ( oids, crcs, offsets) . map ( move |( oid, crc32, ofs32) | Entry {
58
63
oid : gix_hash:: ObjectId :: from_bytes_or_panic ( oid) ,
59
64
pack_offset : self . pack_offset_from_offset_v2 ( ofs32, pack64_offset) ,
60
65
crc32 : Some ( crate :: read_u32 ( crc32) ) ,
@@ -162,10 +167,10 @@ impl index::File {
162
167
index:: Version :: V1 => self . iter ( ) . map ( |e| e. pack_offset ) . collect ( ) ,
163
168
index:: Version :: V2 => {
164
169
let offset32_start = & self . data [ self . offset_pack_offset_v2 ( ) ..] ;
170
+ let offsets32 = offset32_start. chunks_exact ( N32_SIZE ) . take ( self . num_objects as usize ) ;
171
+ assert_eq ! ( self . num_objects as usize , offsets32. len( ) ) ;
165
172
let pack_offset_64_start = self . offset_pack_offset64_v2 ( ) ;
166
- offset32_start
167
- . chunks ( N32_SIZE )
168
- . take ( self . num_objects as usize )
173
+ offsets32
169
174
. map ( |offset| self . pack_offset_from_offset_v2 ( offset, pack_offset_64_start) )
170
175
. collect ( )
171
176
}
0 commit comments