Skip to content

Commit 8b9c5d2

Browse files
ezekielnewrengitster
authored andcommitted
xdiff: change type of xdfile_t.changed from char to bool
The only values possible for 'changed' is 1 and 0, which exactly maps to a bool type. It might not look like this because action1 and action2 (which use to be dis1, and dis2) were also of type char and were assigned numerical values within a few lines of 'changed' (what used to be rchg). Using DISCARD/KEEP/INVESTIGATE for action1[i]/action2[j], and true/false for changed[k] makes it clear to future readers that these are logically separate concepts. Best-viewed-with: --color-words Signed-off-by: Ezekiel Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e385e1b commit 8b9c5d2

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

xdiff/xdiffi.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ int xdl_recs_cmp(xdfile_t *xdf1, long off1, long lim1,
278278
*/
279279
if (off1 == lim1) {
280280
for (; off2 < lim2; off2++)
281-
xdf2->changed[xdf2->rindex[off2]] = 1;
281+
xdf2->changed[xdf2->rindex[off2]] = true;
282282
} else if (off2 == lim2) {
283283
for (; off1 < lim1; off1++)
284-
xdf1->changed[xdf1->rindex[off1]] = 1;
284+
xdf1->changed[xdf1->rindex[off1]] = true;
285285
} else {
286286
xdpsplit_t spl;
287287
spl.i1 = spl.i2 = 0;
@@ -753,8 +753,8 @@ static int group_slide_down(xdfile_t *xdf, struct xdlgroup *g)
753753
{
754754
if (g->end < xdf->nrec &&
755755
recs_match(&xdf->recs[g->start], &xdf->recs[g->end])) {
756-
xdf->changed[g->start++] = 0;
757-
xdf->changed[g->end++] = 1;
756+
xdf->changed[g->start++] = false;
757+
xdf->changed[g->end++] = true;
758758

759759
while (xdf->changed[g->end])
760760
g->end++;
@@ -774,8 +774,8 @@ static int group_slide_up(xdfile_t *xdf, struct xdlgroup *g)
774774
{
775775
if (g->start > 0 &&
776776
recs_match(&xdf->recs[g->start - 1], &xdf->recs[g->end - 1])) {
777-
xdf->changed[--g->start] = 1;
778-
xdf->changed[--g->end] = 0;
777+
xdf->changed[--g->start] = true;
778+
xdf->changed[--g->end] = false;
779779

780780
while (xdf->changed[g->start - 1])
781781
g->start--;
@@ -932,7 +932,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
932932

933933
int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr) {
934934
xdchange_t *cscr = NULL, *xch;
935-
char *changed1 = xe->xdf1.changed, *changed2 = xe->xdf2.changed;
935+
bool *changed1 = xe->xdf1.changed, *changed2 = xe->xdf2.changed;
936936
long i1, i2, l1, l2;
937937

938938
/*

xdiff/xhistogram.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
318318

319319
if (!count1) {
320320
while(count2--)
321-
env->xdf2.changed[line2++ - 1] = 1;
321+
env->xdf2.changed[line2++ - 1] = true;
322322
return 0;
323323
} else if (!count2) {
324324
while(count1--)
325-
env->xdf1.changed[line1++ - 1] = 1;
325+
env->xdf1.changed[line1++ - 1] = true;
326326
return 0;
327327
}
328328

@@ -335,9 +335,9 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
335335
else {
336336
if (lcs.begin1 == 0 && lcs.begin2 == 0) {
337337
while (count1--)
338-
env->xdf1.changed[line1++ - 1] = 1;
338+
env->xdf1.changed[line1++ - 1] = true;
339339
while (count2--)
340-
env->xdf2.changed[line2++ - 1] = 1;
340+
env->xdf2.changed[line2++ - 1] = true;
341341
result = 0;
342342
} else {
343343
result = histogram_diff(xpp, env,

xdiff/xpatience.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
331331
/* trivial case: one side is empty */
332332
if (!count1) {
333333
while(count2--)
334-
env->xdf2.changed[line2++ - 1] = 1;
334+
env->xdf2.changed[line2++ - 1] = true;
335335
return 0;
336336
} else if (!count2) {
337337
while(count1--)
338-
env->xdf1.changed[line1++ - 1] = 1;
338+
env->xdf1.changed[line1++ - 1] = true;
339339
return 0;
340340
}
341341

@@ -347,9 +347,9 @@ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
347347
/* are there any matching lines at all? */
348348
if (!map.has_matches) {
349349
while(count1--)
350-
env->xdf1.changed[line1++ - 1] = 1;
350+
env->xdf1.changed[line1++ - 1] = true;
351351
while(count2--)
352-
env->xdf2.changed[line2++ - 1] = 1;
352+
env->xdf2.changed[line2++ - 1] = true;
353353
xdl_free(map.entries);
354354
return 0;
355355
}

xdiff/xprepare.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
273273

274274
/*
275275
* Create temporary arrays that will help us decide if
276-
* changed[i] should remain 0 or become 1.
276+
* changed[i] should remain false, or become true.
277277
*/
278278
if (!XDL_CALLOC_ARRAY(action1, xdf1->nrec + 1)) {
279279
ret = -1;
@@ -305,16 +305,16 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
305305

306306
/*
307307
* Use temporary arrays to decide if changed[i] should remain
308-
* 0 or become 1.
308+
* false, or become true.
309309
*/
310310
for (nreff = 0, i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart];
311311
i <= xdf1->dend; i++, recs++) {
312312
if (action1[i] == KEEP ||
313313
(action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) {
314314
xdf1->rindex[nreff++] = i;
315-
/* changed[i] remains 0, i.e. keep */
315+
/* changed[i] remains false, i.e. keep */
316316
} else
317-
xdf1->changed[i] = 1;
317+
xdf1->changed[i] = true;
318318
/* i.e. discard */
319319
}
320320
xdf1->nreff = nreff;
@@ -324,9 +324,9 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
324324
if (action2[i] == KEEP ||
325325
(action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) {
326326
xdf2->rindex[nreff++] = i;
327-
/* changed[i] remains 0, i.e. keep */
327+
/* changed[i] remains false, i.e. keep */
328328
} else
329-
xdf2->changed[i] = 1;
329+
xdf2->changed[i] = true;
330330
/* i.e. discard */
331331
}
332332
xdf2->nreff = nreff;

xdiff/xtypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct s_xdfile {
4848
xrecord_t *recs;
4949
long nrec;
5050
long dstart, dend;
51-
char *changed;
51+
bool *changed;
5252
long *rindex;
5353
long nreff;
5454
} xdfile_t;

0 commit comments

Comments
 (0)