Re: [PATCH] mv: prevent mismatched data when ignoring errors.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 18, 2014, 22:31 UTC
- Message-ID
- <xmqqtxav5ebl.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <53270FC2.2030701@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 17 quoted lines
> I had recently been thinking along the same lines. In many of the
> potential callers that I noticed, ALLOC_GROW() was used immediately
> before making space in the array for a new element. So I suggest
> something more like
>
> +#define MOVE_DOWN(array, nr, at, count) \
> + memmove((array) + (at) + (count), \
> + (array) + (at), \
> + sizeof((array)[0]) * ((nr) - (at)))
> +#define ALLOC_INSERT_GAP(array, nr, at, count, alloc) \
> + do { \
> + ALLOC_GROW((array), (nr) + (count), (alloc)); \
> + MOVE_DOWN((array), (nr), (at), (count)); \
> + } while (0)
>
> Also, count==1 is so frequent that this special case might deserve its
> own macro pair.Yeah, probably.
> I'm not inspired by these macro names, though.
Me neither, about ups and downs.
Peff's suggestion to name these around the concept of "gap" sounded sensible.