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

Re: [PATCH] trailer: change strbuf in-place in unfold_value()

From
Jeff King <peff@peff.net>
Date
May 15, 2026, 04:47 UTC
Message-ID
<20260515044703.GD83595@coredump.intra.peff.net>
In-Reply-To
<9629b0c1-b28f-4cd2-8d59-67d909ca9052@web.de>
On Thu, May 14, 2026 at 08:40:56PM +0200, René Scharfe wrote:
Show 8 quoted lines
> Avoid an allocation by doing s/\n\s*/ /g (replacing NL and any following
> whitespace with a SP) right in the strbuf instead of copying the result
> to a temporary one and swapping them in the end.  We can safely do that
> because the replacement is never longer than the original string.
>
> [...]
>
> Inspired by https://lore.kernel.org/git/20260513185408.GA147423@coredump.intra.peff.net/

Cute. Modulo the issue raised by Ramsay, this looks correct to me. In the discussion you referenced I was mostly expecting people to find spots where the solution would be to just remove the strbuf_grow() call. This one is quite a bit trickier, and I am glad to have somebody careful looking at it. ;)

-Peff
Previous: René ScharfeNext: René Scharfe
Message 5 of 6 in “trailer: change strbuf in-place in unfold_value()”
  1. trailer: change strbuf in-place in unfold_value()René Scharfe, May 14, 2026
  2. Ramsay JonesMay 14, 2026
  3. Jeff KingMay 15, 2026
  4. René ScharfeMay 15, 2026
  5. Jeff KingMay 15, 2026
  6. trailer: change strbuf in-place in unfold_value()René Scharfe, May 15, 2026

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.