1
1
use std:: mem:: size_of;
2
2
3
- use byteorder:: { BigEndian , ByteOrder } ;
4
-
5
3
use crate :: {
6
4
data,
7
5
index:: { self , EntryIndex , FAN_LEN } ,
@@ -39,7 +37,7 @@ impl index::File {
39
37
let ( ofs, oid) = c. split_at ( N32_SIZE ) ;
40
38
Entry {
41
39
oid : git_hash:: ObjectId :: from ( oid) ,
42
- pack_offset : BigEndian :: read_u32 ( ofs) as u64 ,
40
+ pack_offset : crate :: read_u32 ( ofs) as u64 ,
43
41
crc32 : None ,
44
42
}
45
43
} ) ,
@@ -59,7 +57,7 @@ impl index::File {
59
57
. map ( move |( oid, crc32, ofs32) | Entry {
60
58
oid : git_hash:: ObjectId :: from ( oid) ,
61
59
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) ) ,
63
61
} ) ,
64
62
_ => panic ! ( "Cannot use iter_v2() on index of type {:?}" , self . version) ,
65
63
}
@@ -94,7 +92,7 @@ impl index::File {
94
92
}
95
93
index:: Version :: V1 => {
96
94
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
98
96
}
99
97
}
100
98
}
@@ -110,7 +108,7 @@ impl index::File {
110
108
match self . version {
111
109
index:: Version :: V2 => {
112
110
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 ] ) )
114
112
}
115
113
index:: Version :: V1 => None ,
116
114
}
@@ -153,14 +151,13 @@ impl index::File {
153
151
let mut ofs: Vec < _ > = match self . version {
154
152
index:: Version :: V1 => self . iter ( ) . map ( |e| e. pack_offset ) . collect ( ) ,
155
153
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 ( )
164
161
}
165
162
} ;
166
163
ofs. sort_unstable ( ) ;
@@ -185,10 +182,10 @@ impl index::File {
185
182
#[ inline]
186
183
fn pack_offset_from_offset_v2 ( & self , offset : & [ u8 ] , pack64_offset : usize ) -> data:: Offset {
187
184
debug_assert_eq ! ( self . version, index:: Version :: V2 ) ;
188
- let ofs32 = BigEndian :: read_u32 ( offset) ;
185
+ let ofs32 = crate :: read_u32 ( offset) ;
189
186
if ( ofs32 & N32_HIGH_BIT ) == N32_HIGH_BIT {
190
187
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 ] )
192
189
} else {
193
190
ofs32 as u64
194
191
}
0 commit comments