Re: [PATCH 1/3] refactor dir_add_name
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 12, 2007, 07:13 UTC
- Message-ID
- <7v7iq9lk76.fsf@assigned-by-dhcp.pobox.com>
- In-Reply-To
- <20070611194651.GA15309@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 19 quoted lines
> ... But we could do something like
> (totally untested):
>
> #define alloc_grow(x, nr, alloc) \
> alloc_grow_helper(&(x), nr, &(alloc), sizeof(*(x)))
>
> inline
> void alloc_grow_helper(void **x, int nr, int *alloc, int size)
> {
> if (nr >= *alloc) {
> *alloc = alloc_nr(*alloc);
> *x = xrealloc(*x, *alloc * size);
> }
> }
>
> Horribly ugly (I'm seeing stars!) but probably a bit safer in the long
> run, and nobody needs to look at it most of the time. :)
>
> What do you think?That looks ugly and also I am curious what the generated assembly would look like. Hopefully the compiler is clever enough to generate the same code, but I dunno.
Unless somebody else more versed with C preprocessor tricks comes along and offers a better advice, I would go with the earlier simpler one with a big fat warning. I however would prefer all caps name for a magic macro like this, whose sole point is a huge side effect.
Anyway, it appears that Jonas picked up your patch to polish up, so I won't touch this series until that resurfaces.