@@ -776,7 +776,6 @@ struct moved_entry {
776
776
struct hashmap_entry ent ;
777
777
const struct emitted_diff_symbol * es ;
778
778
struct moved_entry * next_line ;
779
- struct ws_delta * wsd ;
780
779
};
781
780
782
781
/**
@@ -793,6 +792,17 @@ struct ws_delta {
793
792
};
794
793
#define WS_DELTA_INIT { NULL, 0 }
795
794
795
+ struct moved_block {
796
+ struct moved_entry * match ;
797
+ struct ws_delta wsd ;
798
+ };
799
+
800
+ static void moved_block_clear (struct moved_block * b )
801
+ {
802
+ FREE_AND_NULL (b -> wsd .string );
803
+ b -> match = NULL ;
804
+ }
805
+
796
806
static int compute_ws_delta (const struct emitted_diff_symbol * a ,
797
807
const struct emitted_diff_symbol * b ,
798
808
struct ws_delta * out )
@@ -810,7 +820,7 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a,
810
820
static int cmp_in_block_with_wsd (const struct diff_options * o ,
811
821
const struct moved_entry * cur ,
812
822
const struct moved_entry * match ,
813
- struct moved_entry * pmb ,
823
+ struct moved_block * pmb ,
814
824
int n )
815
825
{
816
826
struct emitted_diff_symbol * l = & o -> emitted_symbols -> buf [n ];
@@ -830,25 +840,24 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
830
840
if (strcmp (a , b ))
831
841
return 1 ;
832
842
833
- if (!pmb -> wsd )
843
+ if (!pmb -> wsd . string )
834
844
/*
835
- * No white space delta was carried forward? This can happen
836
- * when we exit early in this function and do not carry
837
- * forward ws.
845
+ * The white space delta is not active? This can happen
846
+ * when we exit early in this function.
838
847
*/
839
848
return 1 ;
840
849
841
850
/*
842
- * The indent changes of the block are known and carried forward in
851
+ * The indent changes of the block are known and stored in
843
852
* pmb->wsd; however we need to check if the indent changes of the
844
853
* current line are still the same as before.
845
854
*
846
855
* To do so we need to compare 'l' to 'cur', adjusting the
847
856
* one of them for the white spaces, depending which was longer.
848
857
*/
849
858
850
- wslen = strlen (pmb -> wsd -> string );
851
- if (pmb -> wsd -> current_longer ) {
859
+ wslen = strlen (pmb -> wsd . string );
860
+ if (pmb -> wsd . current_longer ) {
852
861
c += wslen ;
853
862
cl -= wslen ;
854
863
} else {
@@ -898,7 +907,6 @@ static struct moved_entry *prepare_entry(struct diff_options *o,
898
907
ret -> ent .hash = xdiff_hash_string (l -> line , l -> len , flags );
899
908
ret -> es = l ;
900
909
ret -> next_line = NULL ;
901
- ret -> wsd = NULL ;
902
910
903
911
return ret ;
904
912
}
@@ -938,76 +946,72 @@ static void add_lines_to_move_detection(struct diff_options *o,
938
946
static void pmb_advance_or_null (struct diff_options * o ,
939
947
struct moved_entry * match ,
940
948
struct hashmap * hm ,
941
- struct moved_entry * * pmb ,
949
+ struct moved_block * pmb ,
942
950
int pmb_nr )
943
951
{
944
952
int i ;
945
953
for (i = 0 ; i < pmb_nr ; i ++ ) {
946
- struct moved_entry * prev = pmb [i ];
954
+ struct moved_entry * prev = pmb [i ]. match ;
947
955
struct moved_entry * cur = (prev && prev -> next_line ) ?
948
956
prev -> next_line : NULL ;
949
957
if (cur && !hm -> cmpfn (o , cur , match , NULL )) {
950
- pmb [i ] = cur ;
958
+ pmb [i ]. match = cur ;
951
959
} else {
952
- pmb [i ] = NULL ;
960
+ pmb [i ]. match = NULL ;
953
961
}
954
962
}
955
963
}
956
964
957
965
static void pmb_advance_or_null_multi_match (struct diff_options * o ,
958
966
struct moved_entry * match ,
959
967
struct hashmap * hm ,
960
- struct moved_entry * * pmb ,
968
+ struct moved_block * pmb ,
961
969
int pmb_nr , int n )
962
970
{
963
971
int i ;
964
972
char * got_match = xcalloc (1 , pmb_nr );
965
973
966
974
for (; match ; match = hashmap_get_next (hm , match )) {
967
975
for (i = 0 ; i < pmb_nr ; i ++ ) {
968
- struct moved_entry * prev = pmb [i ];
976
+ struct moved_entry * prev = pmb [i ]. match ;
969
977
struct moved_entry * cur = (prev && prev -> next_line ) ?
970
978
prev -> next_line : NULL ;
971
979
if (!cur )
972
980
continue ;
973
- if (!cmp_in_block_with_wsd (o , cur , match , pmb [i ], n ))
981
+ if (!cmp_in_block_with_wsd (o , cur , match , & pmb [i ], n ))
974
982
got_match [i ] |= 1 ;
975
983
}
976
984
}
977
985
978
986
for (i = 0 ; i < pmb_nr ; i ++ ) {
979
987
if (got_match [i ]) {
980
- /* Carry the white space delta forward */
981
- pmb [i ]-> next_line -> wsd = pmb [i ]-> wsd ;
982
- pmb [i ] = pmb [i ]-> next_line ;
988
+ /* Advance to the next line */
989
+ pmb [i ].match = pmb [i ].match -> next_line ;
983
990
} else {
984
- if (pmb [i ]-> wsd ) {
985
- free (pmb [i ]-> wsd -> string );
986
- FREE_AND_NULL (pmb [i ]-> wsd );
987
- }
988
- pmb [i ] = NULL ;
991
+ moved_block_clear (& pmb [i ]);
989
992
}
990
993
}
991
994
}
992
995
993
- static int shrink_potential_moved_blocks (struct moved_entry * * pmb ,
996
+ static int shrink_potential_moved_blocks (struct moved_block * pmb ,
994
997
int pmb_nr )
995
998
{
996
999
int lp , rp ;
997
1000
998
1001
/* Shrink the set of potential block to the remaining running */
999
1002
for (lp = 0 , rp = pmb_nr - 1 ; lp <= rp ;) {
1000
- while (lp < pmb_nr && pmb [lp ])
1003
+ while (lp < pmb_nr && pmb [lp ]. match )
1001
1004
lp ++ ;
1002
1005
/* lp points at the first NULL now */
1003
1006
1004
- while (rp > -1 && !pmb [rp ])
1007
+ while (rp > -1 && !pmb [rp ]. match )
1005
1008
rp -- ;
1006
1009
/* rp points at the last non-NULL */
1007
1010
1008
1011
if (lp < pmb_nr && rp > -1 && lp < rp ) {
1009
1012
pmb [lp ] = pmb [rp ];
1010
- pmb [rp ] = NULL ;
1013
+ pmb [rp ].match = NULL ;
1014
+ pmb [rp ].wsd .string = NULL ;
1011
1015
rp -- ;
1012
1016
lp ++ ;
1013
1017
}
@@ -1054,7 +1058,7 @@ static void mark_color_as_moved(struct diff_options *o,
1054
1058
struct hashmap * add_lines ,
1055
1059
struct hashmap * del_lines )
1056
1060
{
1057
- struct moved_entry * * pmb = NULL ; /* potentially moved blocks */
1061
+ struct moved_block * pmb = NULL ; /* potentially moved blocks */
1058
1062
int pmb_nr = 0 , pmb_alloc = 0 ;
1059
1063
int n , flipped_block = 1 , block_length = 0 ;
1060
1064
@@ -1083,7 +1087,11 @@ static void mark_color_as_moved(struct diff_options *o,
1083
1087
}
1084
1088
1085
1089
if (!match ) {
1090
+ int i ;
1091
+
1086
1092
adjust_last_block (o , n , block_length );
1093
+ for (i = 0 ; i < pmb_nr ; i ++ )
1094
+ moved_block_clear (& pmb [i ]);
1087
1095
pmb_nr = 0 ;
1088
1096
block_length = 0 ;
1089
1097
continue ;
@@ -1111,14 +1119,12 @@ static void mark_color_as_moved(struct diff_options *o,
1111
1119
ALLOC_GROW (pmb , pmb_nr + 1 , pmb_alloc );
1112
1120
if (o -> color_moved_ws_handling &
1113
1121
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE ) {
1114
- struct ws_delta * wsd = xmalloc (sizeof (* match -> wsd ));
1115
- if (compute_ws_delta (l , match -> es , wsd )) {
1116
- match -> wsd = wsd ;
1117
- pmb [pmb_nr ++ ] = match ;
1118
- } else
1119
- free (wsd );
1122
+ if (compute_ws_delta (l , match -> es ,
1123
+ & pmb [pmb_nr ].wsd ))
1124
+ pmb [pmb_nr ++ ].match = match ;
1120
1125
} else {
1121
- pmb [pmb_nr ++ ] = match ;
1126
+ pmb [pmb_nr ].wsd .string = NULL ;
1127
+ pmb [pmb_nr ++ ].match = match ;
1122
1128
}
1123
1129
}
1124
1130
@@ -1135,6 +1141,8 @@ static void mark_color_as_moved(struct diff_options *o,
1135
1141
}
1136
1142
adjust_last_block (o , n , block_length );
1137
1143
1144
+ for (n = 0 ; n < pmb_nr ; n ++ )
1145
+ moved_block_clear (& pmb [n ]);
1138
1146
free (pmb );
1139
1147
}
1140
1148
0 commit comments