Skip to content

Commit 506bf09

Browse files
jacob-kellermhagger
authored andcommitted
xdiff: add recs_match helper function
It is a common pattern in xdl_change_compact to check that hashes and strings match. The resulting code to perform this change causes very long lines and makes it hard to follow the intention. Introduce a helper function recs_match which performs both checks to increase code readability. Original Git commit: 92e5b62fec0e9b647429e8d3736c571c434dd375
1 parent 89c332e commit 506bf09

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/xdiff/xdiffi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
404404
}
405405

406406

407+
static int recs_match(xrecord_t **recs, long ixs, long ix, long flags)
408+
{
409+
return (recs[ixs]->ha == recs[ix]->ha &&
410+
xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size,
411+
recs[ix]->ptr, recs[ix]->size,
412+
flags));
413+
}
414+
407415
int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
408416
long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;
409417
char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
@@ -446,8 +454,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
446454
* the last line of the current change group, shift backward
447455
* the group.
448456
*/
449-
while (ixs > 0 && recs[ixs - 1]->ha == recs[ix - 1]->ha &&
450-
xdl_recmatch(recs[ixs - 1]->ptr, recs[ixs - 1]->size, recs[ix - 1]->ptr, recs[ix - 1]->size, flags)) {
457+
while (ixs > 0 && recs_match(recs, ixs - 1, ix - 1, flags)) {
451458
rchg[--ixs] = 1;
452459
rchg[--ix] = 0;
453460

@@ -474,8 +481,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
474481
* the line next of the current change group, shift forward
475482
* the group.
476483
*/
477-
while (ix < nrec && recs[ixs]->ha == recs[ix]->ha &&
478-
xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size, recs[ix]->ptr, recs[ix]->size, flags)) {
484+
while (ix < nrec && recs_match(recs, ixs, ix, flags)) {
479485
rchg[ixs++] = 0;
480486
rchg[ix++] = 1;
481487

0 commit comments

Comments
 (0)