Re: [RFC PATCH 02/14] strvec: introduce `strvec_init_alloc()`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Feb 27, 2026, 03:07 UTC
- Message-ID
- <aaEKYGWi7nd1VLJc@nand.local>
- In-Reply-To
- <xmqq4in3xlvb.fsf@gitster.g>
On Thu, Feb 26, 2026 at 12:58:48PM -0800, Junio C Hamano wrote:
Show 13 quoted lines
> > It is not satisifying that strvec_init() does *not* become a thin > > wrapper around this that says "my initial allocation is for zero > > elements", but that cannot be done easily as a strvec that begins as > > an empty one has a small optimization to avoid one-slot allocation > > only to store NULL. So, ... OK. > > Actually, we should do the same optimization if a caller explicitly > asks > > strvec_init_alloc(&array, 0); > > So perhaps we could do this if we wanted to encapsulate the tricky > bits in a single place for maintainability.
Ah, that is a very satisfying change. I like it and squashed it into my series with your:
Helped-by: Junio C Hamano <gitster@pobox.com>
Show 5 quoted lines
> void strvec_init(struct strvec *array)
> {
> - struct strvec blank = STRVEC_INIT;
> - memcpy(array, &blank, sizeof(*array));
> + strvec_init(array, 0);I suspect you meant `strvec_init_alloc()` here and not `strvec_init()`, but I applied the change and adjusted the typo before squashing it in.
Thanks, Taylor