Subject: Re: [PATCH v5 05/13] xdiff: delete superfluous local variables that alias fields in xrecord_t

From: Phillip Wood <[email-masked]>
Date: Wed, 24 Sep 2025 11:22:21 +0100

On 23/09/2025 22:24, Ezekiel Newren via GitGitGadget wrote:
> From: Ezekiel Newren <[email-masked]>
> 
> Use the type xrecord_t as the local variable for the functions in the
> file xdiff/xemit.c.

This explains what the change is but not why it is being made. Commit 
messages in this project are expected to explain the reason for the 
change so that future readers can understand why a change was made.

Thanks

Phillip

> 
> Signed-off-by: Ezekiel Newren <[email-masked]>
> ---
>   xdiff/xemit.c | 29 +++++++++++++----------------
>   1 file changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/xdiff/xemit.c b/xdiff/xemit.c
> index 40fc8154f3..2161ac3cd0 100644
> --- a/xdiff/xemit.c
> +++ b/xdiff/xemit.c
> @@ -23,12 +23,11 @@
>   #include "xinclude.h"
>   
>   
> -static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) {
> -	long size, psize = strlen(pre);
> -	char const *rec = xdf->recs[ri]->ptr;
> +static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb)
> +{
> +	xrecord_t *rec = xdf->recs[ri];
>   
> -	size = xdf->recs[ri]->size;
> -	if (xdl_emit_diffrec(rec, size, pre, psize, ecb) < 0)
> +	if (xdl_emit_diffrec(rec->ptr, rec->size, pre, strlen(pre), ecb) < 0)
>   		return -1;
>   
>   	return 0;
> @@ -111,11 +110,11 @@ static long def_ff(const char *rec, long len, char *buf, long sz)
>   static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
>   			   char *buf, long sz)
>   {
> -	const char *rec = xdf->recs[ri]->ptr;
> -	long len = xdf->recs[ri]->size;
> +	xrecord_t *rec = xdf->recs[ri];
> +
>   	if (!xecfg->find_func)
> -		return def_ff(rec, len, buf, sz);
> -	return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
> +		return def_ff(rec->ptr, rec->size, buf, sz);
> +	return xecfg->find_func(rec->ptr, rec->size, buf, sz, xecfg->find_func_priv);
>   }
>   
>   static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
> @@ -151,14 +150,12 @@ static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
>   
>   static int is_empty_rec(xdfile_t *xdf, long ri)
>   {
> -	const char *rec = xdf->recs[ri]->ptr;
> -	long len = xdf->recs[ri]->size;
> +	xrecord_t *rec = xdf->recs[ri];
> +	long i = 0;
>   
> -	while (len > 0 && XDL_ISSPACE(*rec)) {
> -		rec++;
> -		len--;
> -	}
> -	return !len;
> +	for (; i < rec->size && XDL_ISSPACE(rec->ptr[i]); i++);
> +
> +	return i == rec->size;
>   }
>   
>   int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,