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. Helped-by: Phillip Wood Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ezekiel Newren committed
Apr 29, 2026 at 22:08 UTC
f99a023df2c3024ccfedc4e1259d5b0732154461
1 file changed
+19
-7
xdiff/xprepare.c
+19
-7
@@ -268,7 +268,7 @@ static bool xdl_clean_mmatch(uint8_t const *action, ptrdiff_t i, ptrdiff_t s, pt
268
* might be potentially discarded if they appear in a run of discardable.
269
*/
270
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;
272
xdlclass_t *rcrec;
273
uint8_t *action1 = NULL, *action2 = NULL;
274
bool need_min = !!(cf->flags & XDF_NEED_MINIMAL);
@@ -290,22 +290,34 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
290
/*
291
* Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
292
*/
293
- if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
294
- mlim = XDL_MAX_EQLIMIT;
293
+ if (need_min) {
294
+ /* i.e. infinity */
295
+ mlim1 = PTRDIFF_MAX;
296
+ } else {
297
+ mlim1 = xdl_bogosqrt((uint64_t)xdf1->nrec);
298
+ if (mlim1 > XDL_MAX_EQLIMIT)
299
+ mlim1 = XDL_MAX_EQLIMIT;
300
+ }
301
for (i = xdf1->dstart; i <= xdf1->dend; i++) {
302
size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
303
rcrec = cf->rcrecs[mph1];
304
nm = rcrec ? rcrec->len2 : 0;
299
- action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
305
+ action1[i] = (nm == 0) ? DISCARD: nm >= mlim1 ? INVESTIGATE: KEEP;
306
}
307
302
- if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
303
- mlim = XDL_MAX_EQLIMIT;
308
+ if (need_min) {
309
+ /* i.e. infinity */
310
+ mlim2 = PTRDIFF_MAX;
311
+ } else {
312
+ mlim2 = xdl_bogosqrt((uint64_t)xdf2->nrec);
313
+ if (mlim2 > XDL_MAX_EQLIMIT)
314
+ mlim2 = XDL_MAX_EQLIMIT;
315
+ }
316
for (i = xdf2->dstart; i <= xdf2->dend; i++) {
317
size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
318
rcrec = cf->rcrecs[mph2];
319
nm = rcrec ? rcrec->len1 : 0;
308
- action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
320
+ action2[i] = (nm == 0) ? DISCARD: nm >= mlim2 ? INVESTIGATE: KEEP;
321
}
322
323
/*