Re: [PATCH v4 5/6] xdiff/xdl_cleanup_records: make setting action easier to follow
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 30, 2026, 23:02 UTC
- Message-ID
- <xmqqy0j86hva.fsf@gitster.g>
- In-Reply-To
- <0cf1412d01cc4895aa945b6f3ead3b2d79716523.1774890003.git.gitgitgadget@gmail.com>
"Ezekiel Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> From: Ezekiel Newren <ezekielnewren@gmail.com> > > Rewrite nested ternaries with a clear if/else ladder for > action1/action2 to improve readability while preserving > behavior. > > Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> > --- > xdiff/xprepare.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-)
Oh, I love this kind of rewrite that makes it more trivial to follwo what the code is doing. Looking good.
Show 31 quoted lines
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index bd8baf214d..471d9567c9 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -303,14 +303,24 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
> size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
> rcrec = cf->rcrecs[mph1];
> nm = rcrec ? rcrec->len2 : 0;
> - action1[i] = (nm == 0) ? DISCARD: nm >= mlim1 ? INVESTIGATE: KEEP;
> + if (nm == 0)
> + action1[i] = DISCARD;
> + else if (nm < mlim1)
> + action1[i] = KEEP;
> + else /* nm >= mlim1 */
> + action1[i] = INVESTIGATE;
> }
>
> 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 >= mlim2 ? INVESTIGATE: KEEP;
> + if (nm == 0)
> + action2[i] = DISCARD;
> + else if (nm < mlim2)
> + action2[i] = KEEP;
> + else /* nm >= mlim2 */
> + action2[i] = INVESTIGATE;
> }
>
> /*