@@ -5,8 +5,6 @@ use std::{
5
5
slice:: Chunks ,
6
6
} ;
7
7
8
- use byteorder:: { BigEndian , ByteOrder } ;
9
-
10
8
use crate :: {
11
9
file:: { self , File , EXTENDED_EDGES_MASK , LAST_EXTENDED_EDGE_MASK , NO_PARENT } ,
12
10
graph,
@@ -38,17 +36,23 @@ pub struct Commit<'a> {
38
36
root_tree_id : & ' a git_hash:: oid ,
39
37
}
40
38
39
+ #[ inline]
40
+ fn read_u32 ( b : & [ u8 ] ) -> u32 {
41
+ u32:: from_be_bytes ( b. try_into ( ) . unwrap ( ) )
42
+ }
43
+
41
44
impl < ' a > Commit < ' a > {
42
45
pub ( crate ) fn new ( file : & ' a File , pos : file:: Position ) -> Self {
43
46
let bytes = file. commit_data_bytes ( pos) ;
44
47
Commit {
45
48
file,
46
49
pos,
47
50
root_tree_id : git_hash:: oid:: from_bytes_unchecked ( & bytes[ ..file. hash_len ] ) ,
48
- parent1 : ParentEdge :: from_raw ( BigEndian :: read_u32 ( & bytes[ file. hash_len ..] [ ..4 ] ) ) ,
49
- parent2 : ParentEdge :: from_raw ( BigEndian :: read_u32 ( & bytes[ file. hash_len + 4 ..] [ ..4 ] ) ) ,
50
- generation : BigEndian :: read_u32 ( & bytes[ file. hash_len + 8 ..] [ ..4 ] ) >> 2 ,
51
- commit_timestamp : BigEndian :: read_u64 ( & bytes[ file. hash_len + 8 ..] [ ..8 ] ) & 0x0003_ffff_ffff ,
51
+ parent1 : ParentEdge :: from_raw ( read_u32 ( & bytes[ file. hash_len ..] [ ..4 ] ) ) ,
52
+ parent2 : ParentEdge :: from_raw ( read_u32 ( & bytes[ file. hash_len + 4 ..] [ ..4 ] ) ) ,
53
+ generation : read_u32 ( & bytes[ file. hash_len + 8 ..] [ ..4 ] ) >> 2 ,
54
+ commit_timestamp : u64:: from_be_bytes ( bytes[ file. hash_len + 8 ..] [ ..8 ] . try_into ( ) . unwrap ( ) )
55
+ & 0x0003_ffff_ffff ,
52
56
}
53
57
}
54
58
@@ -173,7 +177,7 @@ impl<'a> Iterator for ParentIterator<'a> {
173
177
} ,
174
178
ParentIteratorState :: Extra ( mut chunks) => {
175
179
if let Some ( chunk) = chunks. next ( ) {
176
- let extra_edge = BigEndian :: read_u32 ( chunk) ;
180
+ let extra_edge = read_u32 ( chunk) ;
177
181
match ExtraEdge :: from_raw ( extra_edge) {
178
182
ExtraEdge :: Internal ( pos) => {
179
183
self . state = ParentIteratorState :: Extra ( chunks) ;
0 commit comments