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

Re: [PATCH v2] merge-ort: only do pointer arithmetic for non-empty lists

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 12, 2021, 17:47 UTC
Message-ID
<xmqqo8eje6oo.fsf@gitster.g>
In-Reply-To
<CABPp-BE2D933Bc6w-OeaJc1r+1_tvMeK2M-HK4eEKPkQb3BdQQ@mail.gmail.com>
Elijah Newren <newren@gmail.com> writes:
Show 8 quoted lines
>>         /* Pre-allocate some space in buf */
>>         extra = hash_size + 8; /* 8: 6 for mode, 1 for space, 1 for NUL char */
>>
>> base-commit: 89b43f80a514aee58b662ad606e6352e03eaeee4
>> --
>> gitgitgadget
>
> Otherwise, this patch looks good to me; thanks!
By the way, I noticed the post-context comment and got curious.
	/* Pre-allocate some space in buf */
	extra = hash_size + 8; /* 8: 6 for mode, 1 for space, 1 for NUL char */
	for (i = 0; i < nr; i++) {
		maxlen += strlen(versions->items[offset+i].string) + extra;
	}
	strbuf_grow(&buf, maxlen);

Because "6 for mode" is wrong if it means "%06o", but the format used in the code is "%o" so there is no correctness issues in the code (Phew). This "grow" is to avoid having to repeatedly reallocate "nr" times in the loop that comes, but

 (1) s/6 for mode/up to 6 for mode/ to make it less misleading.
 (2) does this preallocation really help performance?
 (3) it is really disturbing to find a custom tree-writing code that
     is exercised only by ort here.  Tree-writing has been one major
     source of broken objects in various reimplementation of Git---
     all known ones made a mistake sometime in the past---and I'd
     strongly prefer to see a single helper that formats a tree
     object, given a set of <mode, object name, path> in the longer
     code health.
Previous: Junio C Hamano
Message 9 of 9 in “merge-ort: only do pointer arithmetic for non-empty lists”
  1. merge-ort: only do pointer arithmetic for non-empty listsAndrzej Hunt via GitGitGadget, Apr 10, 2021
  2. René ScharfeApr 10, 2021
  3. Junio C HamanoApr 10, 2021
  4. Andrzej HuntApr 11, 2021
  5. Andrzej HuntApr 11, 2021
  6. merge-ort: only do pointer arithmetic for non-empty listsAndrzej Hunt via GitGitGadget, Apr 11, 2021
  7. Elijah NewrenApr 12, 2021
  8. Junio C HamanoApr 12, 2021
  9. Junio C HamanoApr 12, 2021

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.