diff options
author | René Scharfe <l.s.r@web.de> | 2014-09-16 20:56:48 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-09-18 09:13:38 -0700 |
commit | 3ac22f82edec108986b2627fcd6f2a8039617a23 (patch) | |
tree | 91f4cd65a867a4808d731e61e63b90d2abbea29e /git-compat-util.h | |
parent | ce1d3a93a6405b8a0313491df3099919ed3d150f (diff) | |
download | git-3ac22f82edec108986b2627fcd6f2a8039617a23.tar.gz |
add macro REALLOC_ARRAY
The macro ALLOC_GROW manages several aspects of dynamic memory
allocations for arrays: It performs overprovisioning in order to avoid
reallocations in future calls, updates the allocation size variable,
multiplies the item size and thus allows users to simply specify the
item count, performs the reallocation and updates the array pointer.
Sometimes this is too much. Add the macro REALLOC_ARRAY, which only
takes care of the latter three points and allows users to specfiy the
number of items the array can store. It can increase and also decrease
the size. Using the macro avoid duplicating the variable name and
takes care of the item sizes automatically.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 4e7e3f8726..5a15b53d67 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -626,6 +626,8 @@ extern int odb_mkstemp(char *template, size_t limit, const char *pattern); extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1); extern char *xgetcwd(void); +#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x))) + static inline size_t xsize_t(off_t len) { if (len > (size_t) len) |