inline xalloc_flex() into FLEXPTR_ALLOC_MEM

Allocate and copy directly in FLEXPTR_ALLOC_MEM and remove the now unused helper function xalloc_flex(). The resulting code is shorter and the offset arithmetic is a bit simpler. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 16, 2016 at 12:06 UTC 0ac52a38e8008fa5bb243e150031681420c639fa
1 file changed +3 -9
git-compat-util.h
+3 -9
@@ -820,7 +820,9 @@ extern FILE *fopen_for_writing(const char *path);
820 memcpy((void *)(x)->flexname, (buf), flex_array_len_); \
821 } while (0)
822 #define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \
823 - (x) = xalloc_flex(sizeof(*(x)), sizeof(*(x)), (buf), (len)); \
823 + size_t flex_array_len_ = (len); \
824 + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \
825 + memcpy((x) + 1, (buf), flex_array_len_); \
826 (x)->ptrname = (void *)((x)+1); \
827 } while(0)
828 #define FLEX_ALLOC_STR(x, flexname, str) \
@@ -828,14 +830,6 @@ extern FILE *fopen_for_writing(const char *path);
830 #define FLEXPTR_ALLOC_STR(x, ptrname, str) \
831 FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))
832
831 -static inline void *xalloc_flex(size_t base_len, size_t offset,
832 - const void *src, size_t src_len)
833 -{
834 - unsigned char *ret = xcalloc(1, st_add3(base_len, src_len, 1));
835 - memcpy(ret + offset, src, src_len);
836 - return ret;
837 -}
838 -
833 static inline char *xstrdup_or_null(const char *str)
834 {
835 return str ? xstrdup(str) : NULL;