Skip to content

Commit eb3de5b

Browse files
committed
Merge branch 'js/xdiffi-comment-updates'
Comment update. * js/xdiffi-comment-updates: xdiffi: fix typos and touch up comments
2 parents 4e8371e + 03d3b12 commit eb3de5b

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

xdiff/xdiffi.c

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ typedef struct s_xdpsplit {
3838
* Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
3939
* the forward diagonal starting from (off1, off2) and the backward diagonal
4040
* 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.
4444
*/
4545
static long xdl_split(unsigned long const *ha1, long off1, long lim1,
4646
unsigned long const *ha2, long off2, long lim2,
@@ -63,11 +63,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
6363
int got_snake = 0;
6464

6565
/*
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
6767
* 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+
*
6971
* 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.
7173
*/
7274
if (fmin > dmin)
7375
kvdf[--fmin - 1] = -1;
@@ -98,11 +100,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
98100
}
99101

100102
/*
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
102104
* 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+
*
104108
* 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.
106110
*/
107111
if (bmin > dmin)
108112
kvdb[--bmin - 1] = XDL_LINE_MAX;
@@ -138,7 +142,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
138142
/*
139143
* If the edit cost is above the heuristic trigger and if
140144
* 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
142146
* measure is a function of the distance from the diagonal
143147
* corner (i1 + i2) penalized with the distance from the
144148
* 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,
196200
}
197201

198202
/*
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.
201206
*/
202207
if (ec >= xenv->mxcost) {
203208
long fbest, fbest1, bbest, bbest1;
@@ -244,9 +249,9 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
244249

245250

246251
/*
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.
250255
*/
251256
int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1,
252257
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,
323328
}
324329

325330
/*
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+
*
327334
* One is to store the forward path and one to store the backward path.
328335
*/
329336
ndiags = xe->xdf1.nreff + xe->xdf2.nreff + 3;
@@ -394,8 +401,8 @@ static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
394401
/*
395402
* If a line is indented more than this, get_indent() just returns this value.
396403
* 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.
399406
*/
400407
#define MAX_INDENT 200
401408

@@ -429,9 +436,9 @@ static int get_indent(xrecord_t *rec)
429436
}
430437

431438
/*
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.
435442
*/
436443
#define MAX_BLANKS 20
437444

@@ -443,8 +450,8 @@ struct split_measurement {
443450
int end_of_file;
444451

445452
/*
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):
448455
*/
449456
int indent;
450457

@@ -454,8 +461,8 @@ struct split_measurement {
454461
int pre_blank;
455462

456463
/*
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)?
459466
*/
460467
int pre_indent;
461468

@@ -581,13 +588,13 @@ static void measure_split(const xdfile_t *xdf, long split,
581588

582589
/*
583590
* 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
586593
*
587594
* https://github.com/mhagger/diff-slider-tools
588595
*
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.
591598
*/
592599
static void score_add_split(const struct split_measurement *m, struct split_score *s)
593600
{
@@ -809,13 +816,16 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
809816
group_init(xdfo, &go);
810817

811818
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+
*/
813822
if (g.end == g.start)
814823
goto next;
815824

816825
/*
817826
* 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.
819829
*/
820830
do {
821831
groupsize = g.end - g.start;
@@ -858,17 +868,17 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
858868
* If the group can be shifted, then we can possibly use this
859869
* freedom to produce a more intuitive diff.
860870
*
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.
863873
*/
864874

865875
if (g.end == earliest_end) {
866876
/* no shifting was possible */
867877
} else if (end_matching_other != -1) {
868878
/*
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.
872882
*/
873883
while (go.end == go.start) {
874884
if (group_slide_up(xdf, &g, flags))
@@ -879,14 +889,15 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
879889
} else if (flags & XDF_INDENT_HEURISTIC) {
880890
/*
881891
* 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.
890901
*/
891902
long shift, best_shift = -1;
892903
struct split_score best_score;

0 commit comments

Comments
 (0)