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 <jacob.e.keller@intel.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Apr 15, 2016 at 16:01 UTC 92e5b62fec0e9b647429e8d3736c571c434dd375
1 file changed +10 -4
xdiff/xdiffi.c
+10 -4
@@ -400,6 +400,14 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
400 }
401
402
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 +
411 int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
412 long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;
413 char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
@@ -442,8 +450,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
450 * the last line of the current change group, shift backward
451 * the group.
452 */
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)) {
454 rchg[--ixs] = 1;
455 rchg[--ix] = 0;
456
@@ -470,8 +477,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
477 * the line next of the current change group, shift forward
478 * the group.
479 */
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)) {
481 rchg[ixs++] = 0;
482 rchg[ix++] = 1;
483