From: Jeff King Date: Fri, 15 May 2026 04:47:03 GMT Subject: Re: [PATCH] trailer: change strbuf in-place in unfold_value() 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: > 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