1
1
use std:: {
2
2
borrow:: Cow ,
3
- collections:: { BTreeMap , VecDeque } ,
3
+ collections:: VecDeque ,
4
4
ffi:: OsStr ,
5
5
fmt:: { self , Arguments , Write } ,
6
6
io:: ErrorKind ,
@@ -157,15 +157,17 @@ impl OpenRepository {
157
157
. or_else ( || path. file_name ( ) )
158
158
. map_or_else ( || Cow :: Borrowed ( "" ) , OsStr :: to_string_lossy) ;
159
159
160
- let content = match ( formatted, String :: from_utf8 ( blob. take_data ( ) ) ) {
160
+ let content = match ( formatted, simdutf8 :: basic :: from_utf8 ( & blob. data ) ) {
161
161
( true , Err ( _) ) => Content :: Binary ( vec ! [ ] ) ,
162
162
( true , Ok ( data) ) => Content :: Text ( Cow :: Owned ( format_file (
163
- & data,
163
+ data,
164
164
& extension,
165
165
& self . git . syntax_set ,
166
166
) ?) ) ,
167
- ( false , Err ( e) ) => Content :: Binary ( e. into_bytes ( ) ) ,
168
- ( false , Ok ( data) ) => Content :: Text ( Cow :: Owned ( data) ) ,
167
+ ( false , Err ( _) ) => Content :: Binary ( blob. take_data ( ) ) ,
168
+ ( false , Ok ( _data) ) => Content :: Text ( Cow :: Owned ( unsafe {
169
+ String :: from_utf8_unchecked ( blob. take_data ( ) )
170
+ } ) ) ,
169
171
} ;
170
172
171
173
return Ok ( PathDestination :: File ( FileWithContent {
@@ -295,7 +297,7 @@ impl OpenRepository {
295
297
continue ;
296
298
} ;
297
299
298
- let Ok ( content) = std :: str :: from_utf8 ( & blob. data ) else {
300
+ let Ok ( content) = simdutf8 :: basic :: from_utf8 ( & blob. data ) else {
299
301
continue ;
300
302
} ;
301
303
@@ -757,7 +759,7 @@ fn fetch_diff_and_stats(
757
759
. transpose ( ) ?
758
760
. unwrap_or_else ( || repo. empty_tree ( ) ) ;
759
761
760
- let mut diffs = BTreeMap :: < _ , FileDiff > :: new ( ) ;
762
+ let mut diffs = Vec :: new ( ) ;
761
763
let mut diff_output = String :: new ( ) ;
762
764
763
765
let mut resource_cache = repo. diff_resource_cache_for_tree_diff ( ) ?;
@@ -795,9 +797,9 @@ fn fetch_diff_and_stats(
795
797
diffs. iter ( ) . fold (
796
798
( 0 , 0 , 0 , 0 , 0 ) ,
797
799
|( max_file_name_length, max_change_length, files_changed, insertions, deletions) ,
798
- ( f , stats) | {
800
+ stats| {
799
801
(
800
- max_file_name_length. max ( f . len ( ) ) ,
802
+ max_file_name_length. max ( stats . path . len ( ) ) ,
801
803
max_change_length
802
804
. max ( ( ( stats. insertions + stats. deletions ) . ilog10 ( ) + 1 ) as usize ) ,
803
805
files_changed + 1 ,
@@ -811,7 +813,7 @@ fn fetch_diff_and_stats(
811
813
812
814
let total_changes = insertions + deletions;
813
815
814
- for ( file , diff) in & diffs {
816
+ for diff in & diffs {
815
817
let local_changes = diff. insertions + diff. deletions ;
816
818
let width = WIDTH . min ( local_changes) ;
817
819
@@ -829,6 +831,7 @@ fn fetch_diff_and_stats(
829
831
let plus_str = "+" . repeat ( adjusted_addition_width) ;
830
832
let minus_str = "-" . repeat ( adjusted_deletion_width) ;
831
833
834
+ let file = diff. path . as_str ( ) ;
832
835
writeln ! ( diff_stats, " {file:max_file_name_length$} | {local_changes:max_change_length$} {plus_str}{minus_str}" ) . unwrap ( ) ;
833
836
}
834
837
@@ -864,6 +867,7 @@ fn fetch_diff_and_stats(
864
867
865
868
#[ derive( Default , Debug ) ]
866
869
struct FileDiff {
870
+ path : String ,
867
871
insertions : usize ,
868
872
deletions : usize ,
869
873
}
@@ -1039,11 +1043,12 @@ trait DiffFormatter {
1039
1043
struct DiffBuilder < ' a , F > {
1040
1044
output : & ' a mut String ,
1041
1045
resource_cache : & ' a mut gix:: diff:: blob:: Platform ,
1042
- diffs : & ' a mut BTreeMap < String , FileDiff > ,
1046
+ diffs : & ' a mut Vec < FileDiff > ,
1043
1047
formatter : F ,
1044
1048
}
1045
1049
1046
1050
impl < ' a , F : DiffFormatter + Callback > DiffBuilder < ' a , F > {
1051
+ #[ allow( clippy:: too_many_lines) ]
1047
1052
fn handle (
1048
1053
& mut self ,
1049
1054
change : gix:: object:: tree:: diff:: Change < ' _ , ' _ , ' _ > ,
@@ -1052,7 +1057,11 @@ impl<'a, F: DiffFormatter + Callback> DiffBuilder<'a, F> {
1052
1057
return Ok ( gix:: object:: tree:: diff:: Action :: Continue ) ;
1053
1058
}
1054
1059
1055
- let diff = self . diffs . entry ( change. location . to_string ( ) ) . or_default ( ) ;
1060
+ let mut diff = FileDiff {
1061
+ path : change. location . to_string ( ) ,
1062
+ insertions : 0 ,
1063
+ deletions : 0 ,
1064
+ } ;
1056
1065
let change = change. diff ( self . resource_cache ) ?;
1057
1066
1058
1067
let prep = change. resource_cache . prepare_diff ( ) ?;
@@ -1129,10 +1138,10 @@ impl<'a, F: DiffFormatter + Callback> DiffBuilder<'a, F> {
1129
1138
. file_header ( self . output , format_args ! ( "+++ {new_path}" ) ) ;
1130
1139
1131
1140
let old_source = gix:: diff:: blob:: sources:: lines_with_terminator (
1132
- std :: str :: from_utf8 ( prep. old . data . as_slice ( ) . unwrap_or_default ( ) ) ?,
1141
+ simdutf8 :: basic :: from_utf8 ( prep. old . data . as_slice ( ) . unwrap_or_default ( ) ) ?,
1133
1142
) ;
1134
1143
let new_source = gix:: diff:: blob:: sources:: lines_with_terminator (
1135
- std :: str :: from_utf8 ( prep. new . data . as_slice ( ) . unwrap_or_default ( ) ) ?,
1144
+ simdutf8 :: basic :: from_utf8 ( prep. new . data . as_slice ( ) . unwrap_or_default ( ) ) ?,
1136
1145
) ;
1137
1146
let input = gix:: diff:: blob:: intern:: InternedInput :: new ( old_source, new_source) ;
1138
1147
@@ -1166,6 +1175,8 @@ impl<'a, F: DiffFormatter + Callback> DiffBuilder<'a, F> {
1166
1175
}
1167
1176
}
1168
1177
1178
+ self . diffs . push ( diff) ;
1179
+
1169
1180
self . resource_cache . clear_resource_cache_keep_allocation ( ) ;
1170
1181
Ok ( gix:: object:: tree:: diff:: Action :: Continue )
1171
1182
}
0 commit comments