Skip to content

Commit 92e5b62

Browse files
jacob-kellergitster
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. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7654286 commit 92e5b62

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

xdiff/xdiffi.c

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

402402

403+
static int recs_match(xrecord_t **recs, long ixs, long ix, long flags)
404+
{
405+
return (recs[ixs]->ha == recs[ix]->ha &&
406+
xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size,
407+
recs[ix]->ptr, recs[ix]->size,
408+
flags));
409+
}
410+
403411
int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
404412
long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;
405413
char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
@@ -442,8 +450,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
442450
* the last line of the current change group, shift backward
443451
* the group.
444452
*/
445-
while (ixs > 0 && recs[ixs - 1]->ha == recs[ix - 1]->ha &&
446-
xdl_recmatch(recs[ixs - 1]->ptr, recs[ixs - 1]->size, recs[ix - 1]->ptr, recs[ix - 1]->size, flags)) {
453+
while (ixs > 0 && recs_match(recs, ixs - 1, ix - 1, flags)) {
447454
rchg[--ixs] = 1;
448455
rchg[--ix] = 0;
449456

@@ -470,8 +477,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
470477
* the line next of the current change group, shift forward
471478
* the group.
472479
*/
473-
while (ix < nrec && recs[ixs]->ha == recs[ix]->ha &&
474-
xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size, recs[ix]->ptr, recs[ix]->size, flags)) {
480+
while (ix < nrec && recs_match(recs, ixs, ix, flags)) {
475481
rchg[ixs++] = 0;
476482
rchg[ix++] = 1;
477483

0 commit comments

Comments
 (0)