Subject: Re: [PATCH 2.5/4] diff: avoid returning a struct by value from diff_flags_or()

From: Brandon Williams <[email-masked]>
Date: Tue, 31 Oct 2017 10:51:19 -0700

On 10/31, Junio C Hamano wrote:
> That is more in line with the design decision made in the previous
> step to pass struct by reference.
> 
> We may want to squash this into the previous patch eventually.

Looks good to me.  I was on the fence with what to do since I was
already moving to pass by reference.  This is probably the better move
so I can squash this one into the previous.

> 
> Signed-off-by: Junio C Hamano <[email-masked]>
> ---
> 
>  * I am OK either way as long as things are consistent; as you took
>    time to change the code to pass the struct by reference, let's
>    unify the API in that direction.
> 
>  diff-lib.c |  2 +-
>  diff.h     | 12 ++++--------
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/diff-lib.c b/diff-lib.c
> index 6c1c05c5b0..ed37f24c68 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -547,7 +547,7 @@ int index_differs_from(const char *def, const struct diff_flags *flags,
>  	DIFF_OPT_SET(&rev.diffopt, QUICK);
>  	DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
>  	if (flags)
> -		rev.diffopt.flags = diff_flags_or(&rev.diffopt.flags, flags);
> +		diff_flags_or(&rev.diffopt.flags, flags);
>  	rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
>  	run_diff_index(&rev, 1);
>  	object_array_clear(&rev.pending);
> diff --git a/diff.h b/diff.h
> index 47e6d43cbc..e512cf44d0 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -94,19 +94,15 @@ struct diff_flags {
>  	unsigned DEFAULT_FOLLOW_RENAMES:1;
>  };
>  
> -static inline struct diff_flags diff_flags_or(const struct diff_flags *a,
> -					      const struct diff_flags *b)
> +static inline void diff_flags_or(struct diff_flags *a,
> +				 const struct diff_flags *b)
>  {
> -	struct diff_flags out;
>  	char *tmp_a = (char *)a;
> -	char *tmp_b = (char *)b;
> -	char *tmp_out = (char *)&out;
> +	const char *tmp_b = (const char *)b;
>  	int i;
>  
>  	for (i = 0; i < sizeof(struct diff_flags); i++)
> -		tmp_out[i] = tmp_a[i] | tmp_b[i];
> -
> -	return out;
> +		tmp_a[i] |= tmp_b[i];
>  }
>  
>  #define DIFF_OPT_TST(opts, flag)	((opts)->flags.flag)
> -- 
> 2.15.0-224-g5109123e6a
> 

-- 
Brandon Williams