diff options
author | Jacob Keller <jacob.keller@gmail.com> | 2016-04-15 16:01:45 -0700 |
---|---|---|
committer | Michael Haggerty <mhagger@alum.mit.edu> | 2016-09-29 17:49:03 +0200 |
commit | 506bf09d51df9fd76b967dc963de626d033f3393 (patch) | |
tree | 362c63bf0b8d0c1d78e8685453cc0158a3f767d6 | |
parent | 89c332e41b12a72d89de40d63bc568c56a2c336a (diff) | |
download | libgit2-506bf09d51df9fd76b967dc963de626d033f3393.tar.gz |
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
-rw-r--r-- | src/xdiff/xdiffi.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/xdiff/xdiffi.c b/src/xdiff/xdiffi.c index f4d01b48c..dbfaf177c 100644 --- a/src/xdiff/xdiffi.c +++ b/src/xdiff/xdiffi.c @@ -404,6 +404,14 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, } +static int recs_match(xrecord_t **recs, long ixs, long ix, long flags) +{ + return (recs[ixs]->ha == recs[ix]->ha && + xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size, + recs[ix]->ptr, recs[ix]->size, + flags)); +} + int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec; char *rchg = xdf->rchg, *rchgo = xdfo->rchg; @@ -446,8 +454,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { * the last line of the current change group, shift backward * the group. */ - while (ixs > 0 && recs[ixs - 1]->ha == recs[ix - 1]->ha && - xdl_recmatch(recs[ixs - 1]->ptr, recs[ixs - 1]->size, recs[ix - 1]->ptr, recs[ix - 1]->size, flags)) { + while (ixs > 0 && recs_match(recs, ixs - 1, ix - 1, flags)) { rchg[--ixs] = 1; rchg[--ix] = 0; @@ -474,8 +481,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { * the line next of the current change group, shift forward * the group. */ - while (ix < nrec && recs[ixs]->ha == recs[ix]->ha && - xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size, recs[ix]->ptr, recs[ix]->size, flags)) { + while (ix < nrec && recs_match(recs, ixs, ix, flags)) { rchg[ixs++] = 0; rchg[ix++] = 1; |