11use std:: mem:: size_of;
22
3- use byteorder:: { BigEndian , ByteOrder } ;
4-
53use crate :: {
64 data,
75 index:: { self , EntryIndex , FAN_LEN } ,
@@ -39,7 +37,7 @@ impl index::File {
3937 let ( ofs, oid) = c. split_at ( N32_SIZE ) ;
4038 Entry {
4139 oid : git_hash:: ObjectId :: from ( oid) ,
42- pack_offset : BigEndian :: read_u32 ( ofs) as u64 ,
40+ pack_offset : crate :: read_u32 ( ofs) as u64 ,
4341 crc32 : None ,
4442 }
4543 } ) ,
@@ -59,7 +57,7 @@ impl index::File {
5957 . map ( move |( oid, crc32, ofs32) | Entry {
6058 oid : git_hash:: ObjectId :: from ( oid) ,
6159 pack_offset : self . pack_offset_from_offset_v2 ( ofs32, pack64_offset) ,
62- crc32 : Some ( BigEndian :: read_u32 ( crc32) ) ,
60+ crc32 : Some ( crate :: read_u32 ( crc32) ) ,
6361 } ) ,
6462 _ => panic ! ( "Cannot use iter_v2() on index of type {:?}" , self . version) ,
6563 }
@@ -94,7 +92,7 @@ impl index::File {
9492 }
9593 index:: Version :: V1 => {
9694 let start = V1_HEADER_SIZE + index * ( N32_SIZE + self . hash_len ) ;
97- BigEndian :: read_u32 ( & self . data [ start..] [ ..N32_SIZE ] ) as u64
95+ crate :: read_u32 ( & self . data [ start..] [ ..N32_SIZE ] ) as u64
9896 }
9997 }
10098 }
@@ -110,7 +108,7 @@ impl index::File {
110108 match self . version {
111109 index:: Version :: V2 => {
112110 let start = self . offset_crc32_v2 ( ) + index * N32_SIZE ;
113- Some ( BigEndian :: read_u32 ( & self . data [ start..start + N32_SIZE ] ) )
111+ Some ( crate :: read_u32 ( & self . data [ start..start + N32_SIZE ] ) )
114112 }
115113 index:: Version :: V1 => None ,
116114 }
@@ -153,14 +151,13 @@ impl index::File {
153151 let mut ofs: Vec < _ > = match self . version {
154152 index:: Version :: V1 => self . iter ( ) . map ( |e| e. pack_offset ) . collect ( ) ,
155153 index:: Version :: V2 => {
156- let mut v = Vec :: with_capacity ( self . num_objects as usize ) ;
157- let mut ofs32 = & self . data [ self . offset_pack_offset_v2 ( ) ..] ;
158- let pack_offset_64 = self . offset_pack_offset64_v2 ( ) ;
159- for _ in 0 ..self . num_objects {
160- v. push ( self . pack_offset_from_offset_v2 ( ofs32, pack_offset_64) ) ;
161- ofs32 = & ofs32[ 4 ..] ;
162- }
163- v
154+ let offset32_start = & self . data [ self . offset_pack_offset_v2 ( ) ..] ;
155+ let pack_offset_64_start = self . offset_pack_offset64_v2 ( ) ;
156+ offset32_start
157+ . chunks ( N32_SIZE )
158+ . take ( self . num_objects as usize )
159+ . map ( |offset| self . pack_offset_from_offset_v2 ( offset, pack_offset_64_start) )
160+ . collect ( )
164161 }
165162 } ;
166163 ofs. sort_unstable ( ) ;
@@ -185,10 +182,10 @@ impl index::File {
185182 #[ inline]
186183 fn pack_offset_from_offset_v2 ( & self , offset : & [ u8 ] , pack64_offset : usize ) -> data:: Offset {
187184 debug_assert_eq ! ( self . version, index:: Version :: V2 ) ;
188- let ofs32 = BigEndian :: read_u32 ( offset) ;
185+ let ofs32 = crate :: read_u32 ( offset) ;
189186 if ( ofs32 & N32_HIGH_BIT ) == N32_HIGH_BIT {
190187 let from = pack64_offset + ( ofs32 ^ N32_HIGH_BIT ) as usize * N64_SIZE ;
191- BigEndian :: read_u64 ( & self . data [ from..] [ ..N64_SIZE ] )
188+ crate :: read_u64 ( & self . data [ from..] [ ..N64_SIZE ] )
192189 } else {
193190 ofs32 as u64
194191 }
0 commit comments