From: Arnav Bhate <bhatearnav@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [GSoC PATCH] decorate: fix sign comparison warnings
Date: Mon, 10 Mar 2025 23:37:07 +0530 [thread overview]
Message-ID: <d68646b7-0513-4a54-a145-cdbd0cd67a4a@gmail.com> (raw)
In-Reply-To: <xmqqikog96uz.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> A simpler fix to the first hunk may be to get rid of the
> intermediate variable altogether and always refer to n->size
> when its value is needed. The compiler should be able to see in
> this static file-scope helper function that n->size would not change
> at all and do the right thing (i.e. allocate a register to hold its
> value at entry, if needed) without a hand-optimization we see in the
> original code.
>
> The same can be said for the second hunk. The intermediate variable
> is used only once, and one could argue that its presense obscures
> the condition under which grow_decoration() is called by splitting a
> logically single expression into two.
>
> Which one is easier to grok?
>
> unsigned nr = n->nr + 1;
> if (nr > n->size * 2 / 3)
> grow_decoration(n);
>
> or
>
> if ((n->nr + 1) > n->size * 2 / 3)
> grow_decoration(n);
Your suggestion makes sense to me, the second one is better. I will send an
updated patch. I also found some more places in the file where a change from
int to unsigned int should happen, but where int does not cause warnings. I
will also include it in the patch.
--
Regards,
Arnav Bhate
(He/Him)
next prev parent reply other threads:[~2025-03-10 18:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 9:51 [GSoC PATCH] decorate: fix sign comparison warnings Arnav Bhate
2025-03-10 16:40 ` Junio C Hamano
2025-03-10 18:07 ` Arnav Bhate [this message]
2025-03-10 18:08 ` [GSoC PATCH v2] " Arnav Bhate
2025-03-10 21:02 ` Karthik Nayak
2025-03-11 18:26 ` Arnav Bhate
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d68646b7-0513-4a54-a145-cdbd0cd67a4a@gmail.com \
--to=bhatearnav@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).