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

Re: [PATCH] Optimize common pattern of alloc_ref from string

From
Krzysztof Kowalczyk <kkowalczyk@gmail.com>
Date
May 11, 2008, 20:15 UTC
Message-ID
<7ce338ad0805111315q3745ea7fn4c38b557170e521f@mail.gmail.com>
In-Reply-To
<7vskwo3ct5.fsf@gitster.siamese.dyndns.org>
On Sun, May 11, 2008 at 11:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> But really my main worry is that now we have _two_ functions which
>> allocate refs, so if "struct ref" ever grows a new field that needs
>> initializing, it has to go in two places (whereas if alloc_ref_from_str
>> calls alloc_ref, it works automatically).
>
> This is a very good point.  We really do not want a micro-optimization in
> a way that hurts maintainability.
>
> Krzysztof's patch has the new function with the duplicated allocation
> implementation between the base allocator function and the existing
> copy_ref() function which also has yet another duplicated allocation
> implementation.  When somebody needs to modify one, it is likely to be
> noticed that these three go hand-in-hand, hopefully ;-).
>
> By the way, why isn't alloc_ref() doing xcalloc(), I have to wonder...
I've sent updated patch that incorporates the feedback. Changes wrt.
to this patch:
* simpler version of alloc_ref_from_str() per Jeff's suggestion
* switches alloc_ref() to xcalloc() per Junio's suggestion
* uses alloc_ref_from_str() in one more place
* better (?) commit message
-- kjk
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 8 in “Optimize common pattern of alloc_ref from string”
  1. Optimize common pattern of alloc_ref from stringkkowalczyk@gmail.com, May 10, 2008
  2. Jeff KingMay 10, 2008
  3. Krzysztof KowalczykMay 11, 2008
  4. Jeff KingMay 11, 2008
  5. Junio C HamanoMay 11, 2008
  6. Krzysztof KowalczykMay 11, 2008
  7. Junio C HamanoMay 11, 2008
  8. Johannes SchindelinMay 11, 2008

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.