]> git.ipfire.org Git - thirdparty/git.git/commitdiff
xdiff/xdl_cleanup_records: make limits more clear
authorEzekiel Newren <ezekielnewren@gmail.com>
Wed, 29 Apr 2026 22:08:13 +0000 (22:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Apr 2026 00:16:50 +0000 (09:16 +0900)
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>
xdiff/xprepare.c

index 386668a92d735858e96b488ae3c27aaa5eb9dd06..7141dbc058f4ae3fda604953b96ff8fd21242b06 100644 (file)
@@ -268,7 +268,7 @@ static bool xdl_clean_mmatch(uint8_t const *action, ptrdiff_t i, ptrdiff_t s, pt
  * might be potentially discarded if they appear in a run of discardable.
  */
 static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
-       ptrdiff_t i, nm, mlim;
+       ptrdiff_t i, nm, mlim1, mlim2;
        xdlclass_t *rcrec;
        uint8_t *action1 = NULL, *action2 = NULL;
        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
        /*
         * Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
         */
-       if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
-               mlim = XDL_MAX_EQLIMIT;
+       if (need_min) {
+               /* i.e. infinity */
+               mlim1 = PTRDIFF_MAX;
+       } else {
+               mlim1 = xdl_bogosqrt((uint64_t)xdf1->nrec);
+               if (mlim1 > XDL_MAX_EQLIMIT)
+                       mlim1 = XDL_MAX_EQLIMIT;
+       }
        for (i = xdf1->dstart; i <= xdf1->dend; i++) {
                size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
                rcrec = cf->rcrecs[mph1];
                nm = rcrec ? rcrec->len2 : 0;
-               action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
+               action1[i] = (nm == 0) ? DISCARD: nm >= mlim1 ? INVESTIGATE: KEEP;
        }
 
-       if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
-               mlim = XDL_MAX_EQLIMIT;
+       if (need_min) {
+               /* i.e. infinity */
+               mlim2 = PTRDIFF_MAX;
+       } else {
+               mlim2 = xdl_bogosqrt((uint64_t)xdf2->nrec);
+               if (mlim2 > XDL_MAX_EQLIMIT)
+                       mlim2 = XDL_MAX_EQLIMIT;
+       }
        for (i = xdf2->dstart; i <= xdf2->dend; i++) {
                size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
                rcrec = cf->rcrecs[mph2];
                nm = rcrec ? rcrec->len1 : 0;
-               action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
+               action2[i] = (nm == 0) ? DISCARD: nm >= mlim2 ? INVESTIGATE: KEEP;
        }
 
        /*