Skip to content

Commit 59cb212

Browse files
ezekielnewrengitster
authored andcommitted
xdiff/xdl_cleanup_records: make limits more clear
Make the handling of per-file limits and the minimal-case clearer. * Use explicit per-file limit variables (mlim1, mlim2) and initialize them. * The additional condition `!need_min` is redudant now, remove it. Best viewed with --color-words. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 042cefe commit 59cb212

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

xdiff/xprepare.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static bool xdl_clean_mmatch(uint8_t const *action, ptrdiff_t i, ptrdiff_t s, pt
268268
* might be potentially discarded if they appear in a run of discardable.
269269
*/
270270
static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
271-
ptrdiff_t i, nm, mlim;
271+
ptrdiff_t i, nm, mlim1, mlim2;
272272
xdlclass_t *rcrec;
273273
uint8_t *action1 = NULL, *action2 = NULL;
274274
bool need_min = !!(cf->flags & XDF_NEED_MINIMAL);
@@ -287,25 +287,30 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
287287
goto cleanup;
288288
}
289289

290+
if (need_min) {
291+
/* i.e. infinity */
292+
mlim1 = PTRDIFF_MAX;
293+
mlim2 = PTRDIFF_MAX;
294+
} else {
295+
mlim1 = XDL_MIN(xdl_bogosqrt(xdf1->nrec), XDL_MAX_EQLIMIT);
296+
mlim2 = XDL_MIN(xdl_bogosqrt(xdf2->nrec), XDL_MAX_EQLIMIT);
297+
}
298+
290299
/*
291300
* Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
292301
*/
293-
if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
294-
mlim = XDL_MAX_EQLIMIT;
295302
for (i = xdf1->dstart; i <= xdf1->dend; i++) {
296303
size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
297304
rcrec = cf->rcrecs[mph1];
298305
nm = rcrec ? rcrec->len2 : 0;
299-
action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
306+
action1[i] = (nm == 0) ? DISCARD: nm >= mlim1 ? INVESTIGATE: KEEP;
300307
}
301308

302-
if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
303-
mlim = XDL_MAX_EQLIMIT;
304309
for (i = xdf2->dstart; i <= xdf2->dend; i++) {
305310
size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
306311
rcrec = cf->rcrecs[mph2];
307312
nm = rcrec ? rcrec->len1 : 0;
308-
action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
313+
action2[i] = (nm == 0) ? DISCARD: nm >= mlim2 ? INVESTIGATE: KEEP;
309314
}
310315

311316
/*

0 commit comments

Comments
 (0)