git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC PATCH] decorate: fix sign comparison warnings

From
Arnav Bhate <bhatearnav@gmail.com>
Date
Mar 10, 2025, 18:07 UTC
Message-ID
<d68646b7-0513-4a54-a145-cdbd0cd67a4a@gmail.com>
In-Reply-To
<xmqqikog96uz.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 23 quoted lines
> 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)
Previous: Junio C HamanoNext: Arnav Bhate
Message 3 of 6 in “decorate: fix sign comparison warnings”
  1. decorate: fix sign comparison warningsArnav Bhate, Mar 10, 2025
  2. Junio C HamanoMar 10, 2025
  3. Arnav BhateMar 10, 2025
  4. decorate: fix sign comparison warningsArnav Bhate, Mar 10, 2025
  5. Karthik NayakMar 10, 2025
  6. Arnav BhateMar 11, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.