summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-10-16 12:06:02 +0200
committerJunio C Hamano <gitster@pobox.com>2016-10-17 14:42:56 -0700
commit0ac52a38e8008fa5bb243e150031681420c639fa (patch)
treee0002e605c44b9316eed9fdbf8074db83700f72e
parente9451782cfbe9fc9105bf63228bca3e2265af8f8 (diff)
downloadgit-0ac52a38e8008fa5bb243e150031681420c639fa.tar.gz
inline xalloc_flex() into FLEXPTR_ALLOC_MEMjk/tighten-alloc
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>
-rw-r--r--git-compat-util.h12
1 files changed, 3 insertions, 9 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 237cef1760..36c4f3acf1 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -820,7 +820,9 @@ extern FILE *fopen_for_writing(const char *path);
memcpy((void *)(x)->flexname, (buf), flex_array_len_); \
} while (0)
#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \
- (x) = xalloc_flex(sizeof(*(x)), sizeof(*(x)), (buf), (len)); \
+ size_t flex_array_len_ = (len); \
+ (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \
+ memcpy((x) + 1, (buf), flex_array_len_); \
(x)->ptrname = (void *)((x)+1); \
} while(0)
#define FLEX_ALLOC_STR(x, flexname, str) \
@@ -828,14 +830,6 @@ extern FILE *fopen_for_writing(const char *path);
#define FLEXPTR_ALLOC_STR(x, ptrname, str) \
FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))
-static inline void *xalloc_flex(size_t base_len, size_t offset,
- const void *src, size_t src_len)
-{
- unsigned char *ret = xcalloc(1, st_add3(base_len, src_len, 1));
- memcpy(ret + offset, src, src_len);
- return ret;
-}
-
static inline char *xstrdup_or_null(const char *str)
{
return str ? xstrdup(str) : NULL;