@@ -38,9 +38,9 @@ typedef struct s_xdpsplit {
38
38
* Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
39
39
* the forward diagonal starting from (off1, off2) and the backward diagonal
40
40
* starting from (lim1, lim2). If the K values on the same diagonal crosses
41
- * returns the furthest point of reach. We might end up having to expensive
42
- * cases using this algorithm is full , so a little bit of heuristic is needed
43
- * to cut the search and to return a suboptimal point.
41
+ * returns the furthest point of reach. We might encounter expensive edge cases
42
+ * using this algorithm, so a little bit of heuristic is needed to cut the
43
+ * search and to return a suboptimal point.
44
44
*/
45
45
static long xdl_split (unsigned long const * ha1 , long off1 , long lim1 ,
46
46
unsigned long const * ha2 , long off2 , long lim2 ,
@@ -63,11 +63,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
63
63
int got_snake = 0 ;
64
64
65
65
/*
66
- * We need to extent the diagonal "domain" by one. If the next
66
+ * We need to extend the diagonal "domain" by one. If the next
67
67
* values exits the box boundaries we need to change it in the
68
- * opposite direction because (max - min) must be a power of two.
68
+ * opposite direction because (max - min) must be a power of
69
+ * two.
70
+ *
69
71
* Also we initialize the external K value to -1 so that we can
70
- * avoid extra conditions check inside the core loop.
72
+ * avoid extra conditions in the check inside the core loop.
71
73
*/
72
74
if (fmin > dmin )
73
75
kvdf [-- fmin - 1 ] = -1 ;
@@ -98,11 +100,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
98
100
}
99
101
100
102
/*
101
- * We need to extent the diagonal "domain" by one. If the next
103
+ * We need to extend the diagonal "domain" by one. If the next
102
104
* values exits the box boundaries we need to change it in the
103
- * opposite direction because (max - min) must be a power of two.
105
+ * opposite direction because (max - min) must be a power of
106
+ * two.
107
+ *
104
108
* Also we initialize the external K value to -1 so that we can
105
- * avoid extra conditions check inside the core loop.
109
+ * avoid extra conditions in the check inside the core loop.
106
110
*/
107
111
if (bmin > dmin )
108
112
kvdb [-- bmin - 1 ] = XDL_LINE_MAX ;
@@ -138,7 +142,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
138
142
/*
139
143
* If the edit cost is above the heuristic trigger and if
140
144
* we got a good snake, we sample current diagonals to see
141
- * if some of the, have reached an "interesting" path. Our
145
+ * if some of them have reached an "interesting" path. Our
142
146
* measure is a function of the distance from the diagonal
143
147
* corner (i1 + i2) penalized with the distance from the
144
148
* mid diagonal itself. If this value is above the current
@@ -196,8 +200,9 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
196
200
}
197
201
198
202
/*
199
- * Enough is enough. We spent too much time here and now we collect
200
- * the furthest reaching path using the (i1 + i2) measure.
203
+ * Enough is enough. We spent too much time here and now we
204
+ * collect the furthest reaching path using the (i1 + i2)
205
+ * measure.
201
206
*/
202
207
if (ec >= xenv -> mxcost ) {
203
208
long fbest , fbest1 , bbest , bbest1 ;
@@ -244,9 +249,9 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
244
249
245
250
246
251
/*
247
- * Rule: "Divide et Impera". Recursively split the box in sub-boxes by calling
248
- * the box splitting function. Note that the real job (marking changed lines)
249
- * is done in the two boundary reaching checks.
252
+ * Rule: "Divide et Impera" (divide & conquer) . Recursively split the box in
253
+ * sub-boxes by calling the box splitting function. Note that the real job
254
+ * (marking changed lines) is done in the two boundary reaching checks.
250
255
*/
251
256
int xdl_recs_cmp (diffdata_t * dd1 , long off1 , long lim1 ,
252
257
diffdata_t * dd2 , long off2 , long lim2 ,
@@ -323,7 +328,9 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
323
328
}
324
329
325
330
/*
326
- * Allocate and setup K vectors to be used by the differential algorithm.
331
+ * Allocate and setup K vectors to be used by the differential
332
+ * algorithm.
333
+ *
327
334
* One is to store the forward path and one to store the backward path.
328
335
*/
329
336
ndiags = xe -> xdf1 .nreff + xe -> xdf2 .nreff + 3 ;
@@ -394,8 +401,8 @@ static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
394
401
/*
395
402
* If a line is indented more than this, get_indent() just returns this value.
396
403
* This avoids having to do absurd amounts of work for data that are not
397
- * human-readable text, and also ensures that the output of get_indent fits within
398
- * an int.
404
+ * human-readable text, and also ensures that the output of get_indent fits
405
+ * within an int.
399
406
*/
400
407
#define MAX_INDENT 200
401
408
@@ -429,9 +436,9 @@ static int get_indent(xrecord_t *rec)
429
436
}
430
437
431
438
/*
432
- * If more than this number of consecutive blank rows are found, just return this
433
- * value. This avoids requiring O(N^2) work for pathological cases, and also
434
- * ensures that the output of score_split fits in an int.
439
+ * If more than this number of consecutive blank rows are found, just return
440
+ * this value. This avoids requiring O(N^2) work for pathological cases, and
441
+ * also ensures that the output of score_split fits in an int.
435
442
*/
436
443
#define MAX_BLANKS 20
437
444
@@ -443,8 +450,8 @@ struct split_measurement {
443
450
int end_of_file ;
444
451
445
452
/*
446
- * How much is the line immediately following the split indented (or -1 if
447
- * the line is blank):
453
+ * How much is the line immediately following the split indented (or -1
454
+ * if the line is blank):
448
455
*/
449
456
int indent ;
450
457
@@ -454,8 +461,8 @@ struct split_measurement {
454
461
int pre_blank ;
455
462
456
463
/*
457
- * How much is the nearest non-blank line above the split indented (or -1
458
- * if there is no such line)?
464
+ * How much is the nearest non-blank line above the split indented (or
465
+ * -1 if there is no such line)?
459
466
*/
460
467
int pre_indent ;
461
468
@@ -581,13 +588,13 @@ static void measure_split(const xdfile_t *xdf, long split,
581
588
582
589
/*
583
590
* Compute a badness score for the hypothetical split whose measurements are
584
- * stored in m. The weight factors were determined empirically using the tools and
585
- * corpus described in
591
+ * stored in m. The weight factors were determined empirically using the tools
592
+ * and corpus described in
586
593
*
587
594
* https://github.com/mhagger/diff-slider-tools
588
595
*
589
- * Also see that project if you want to improve the weights based on, for example,
590
- * a larger or more diverse corpus.
596
+ * Also see that project if you want to improve the weights based on, for
597
+ * example, a larger or more diverse corpus.
591
598
*/
592
599
static void score_add_split (const struct split_measurement * m , struct split_score * s )
593
600
{
@@ -809,13 +816,16 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
809
816
group_init (xdfo , & go );
810
817
811
818
while (1 ) {
812
- /* If the group is empty in the to-be-compacted file, skip it: */
819
+ /*
820
+ * If the group is empty in the to-be-compacted file, skip it:
821
+ */
813
822
if (g .end == g .start )
814
823
goto next ;
815
824
816
825
/*
817
826
* Now shift the change up and then down as far as possible in
818
- * each direction. If it bumps into any other changes, merge them.
827
+ * each direction. If it bumps into any other changes, merge
828
+ * them.
819
829
*/
820
830
do {
821
831
groupsize = g .end - g .start ;
@@ -858,17 +868,17 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
858
868
* If the group can be shifted, then we can possibly use this
859
869
* freedom to produce a more intuitive diff.
860
870
*
861
- * The group is currently shifted as far down as possible, so the
862
- * heuristics below only have to handle upwards shifts.
871
+ * The group is currently shifted as far down as possible, so
872
+ * the heuristics below only have to handle upwards shifts.
863
873
*/
864
874
865
875
if (g .end == earliest_end ) {
866
876
/* no shifting was possible */
867
877
} else if (end_matching_other != -1 ) {
868
878
/*
869
- * Move the possibly merged group of changes back to line
870
- * up with the last group of changes from the other file
871
- * that it can align with.
879
+ * Move the possibly merged group of changes back to
880
+ * line up with the last group of changes from the
881
+ * other file that it can align with.
872
882
*/
873
883
while (go .end == go .start ) {
874
884
if (group_slide_up (xdf , & g , flags ))
@@ -879,14 +889,15 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
879
889
} else if (flags & XDF_INDENT_HEURISTIC ) {
880
890
/*
881
891
* Indent heuristic: a group of pure add/delete lines
882
- * implies two splits, one between the end of the "before"
883
- * context and the start of the group, and another between
884
- * the end of the group and the beginning of the "after"
885
- * context. Some splits are aesthetically better and some
886
- * are worse. We compute a badness "score" for each split,
887
- * and add the scores for the two splits to define a
888
- * "score" for each position that the group can be shifted
889
- * to. Then we pick the shift with the lowest score.
892
+ * implies two splits, one between the end of the
893
+ * "before" context and the start of the group, and
894
+ * another between the end of the group and the
895
+ * beginning of the "after" context. Some splits are
896
+ * aesthetically better and some are worse. We compute
897
+ * a badness "score" for each split, and add the scores
898
+ * for the two splits to define a "score" for each
899
+ * position that the group can be shifted to. Then we
900
+ * pick the shift with the lowest score.
890
901
*/
891
902
long shift , best_shift = -1 ;
892
903
struct split_score best_score ;
0 commit comments