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