Re: [PATCH 06/10] xdiff: cleanup xdl_trim_ends()
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jan 20, 2026, 16:32 UTC
- Message-ID
- <2b6592f6-1d20-4cdd-8af7-f524920ad1a7@gmail.com>
- In-Reply-To
- <65da408da9589420ec341368d0853e6183aee922.1767379944.git.gitgitgadget@gmail.com>
On 02/01/2026 18:52, Ezekiel Newren via GitGitGadget wrote:
Show 8 quoted lines
> From: Ezekiel Newren <ezekielnewren@gmail.com> > > This patch is best viewed with a before and after of the whole > function. > > Rather than using 2 pointers and walking them. Use direct indexing with > local variables of what is being compared to make it easier to follow > along.
I think using direct indexing makes things clearer, but I'm not sure this is a faithful conversion (see below).
Show 26 quoted lines
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index 0acb3437d4..06b6a6f804 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -340,29 +340,29 @@ cleanup:
> /*
> * Early trim initial and terminal matching records.
> */
> -static int xdl_trim_ends(xdfenv_t *xe) {
> - long i, lim;
> - xrecord_t *recs1, *recs2;
> -
> - recs1 = xe->xdf1.recs;
> - recs2 = xe->xdf2.recs;
> - for (i = 0, lim = (long)XDL_MIN(xe->xdf1.nrec, xe->xdf2.nrec); i < lim;
> - i++, recs1++, recs2++)
> - if (recs1->minimal_perfect_hash != recs2->minimal_perfect_hash)
> +static void xdl_trim_ends(xdfenv_t *xe)
> +{
> + size_t lim = XDL_MIN(xe->xdf1.nrec, xe->xdf2.nrec);
> +
> + for (size_t i = 0; i < lim; i++) {
> + size_t mph1 = xe->xdf1.recs[i].minimal_perfect_hash;
> + size_t mph2 = xe->xdf2.recs[i].minimal_perfect_hash;
> + if (mph1 != mph2) {
> + xe->xdf1.dstart = xe->xdf2.dstart = (ssize_t)i;The type of dstart is ptrdiff_t, not ssize_t.
The original set dstart and dend unconditionally but here they are not set if all the lines match.
Thanks
Phillip
Show 28 quoted lines
> + lim -= i;
> break;
> + }
> + }
>
> - xe->xdf1.dstart = xe->xdf2.dstart = i;
> -
> - recs1 = xe->xdf1.recs + xe->xdf1.nrec - 1;
> - recs2 = xe->xdf2.recs + xe->xdf2.nrec - 1;
> - for (lim -= i, i = 0; i < lim; i++, recs1--, recs2--)
> - if (recs1->minimal_perfect_hash != recs2->minimal_perfect_hash)
> + for (size_t i = 0; i < lim; i++) {
> + size_t mph1 = xe->xdf1.recs[xe->xdf1.nrec - 1 - i].minimal_perfect_hash;
> + size_t mph2 = xe->xdf2.recs[xe->xdf2.nrec - 1 - i].minimal_perfect_hash;
> + if (mph1 != mph2) {
> + xe->xdf1.dend = xe->xdf1.nrec - 1 - i;
> + xe->xdf2.dend = xe->xdf2.nrec - 1 - i;
> break;
> -
> - xe->xdf1.dend = (long)xe->xdf1.nrec - i - 1;
> - xe->xdf2.dend = (long)xe->xdf2.nrec - i - 1;
> -
> - return 0;
> + }
> + }
> }
>
>