Skip to content

Commit 0ac52a3

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e945178 commit 0ac52a3

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

git-compat-util.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -820,22 +820,16 @@ extern FILE *fopen_for_writing(const char *path);
820820
memcpy((void *)(x)->flexname, (buf), flex_array_len_); \
821821
} while (0)
822822
#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_); \
824826
(x)->ptrname = (void *)((x)+1); \
825827
} while(0)
826828
#define FLEX_ALLOC_STR(x, flexname, str) \
827829
FLEX_ALLOC_MEM((x), flexname, (str), strlen(str))
828830
#define FLEXPTR_ALLOC_STR(x, ptrname, str) \
829831
FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))
830832

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-
839833
static inline char *xstrdup_or_null(const char *str)
840834
{
841835
return str ? xstrdup(str) : NULL;

0 commit comments

Comments
 (0)