X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=alloc.c;h=216c23a6f854c614d38c743cd7687a37f304161b;hb=a8ccc204c5daf4dae4071907499055d2dc9995db;hp=460db192d5a7de4073eb89972871720dd1c8fe1e;hpb=e94b4d2f2a3a9b2aaaac15c33d5d31f76531ecbf;p=git.git diff --git a/alloc.c b/alloc.c index 460db192d..216c23a6f 100644 --- a/alloc.c +++ b/alloc.c @@ -18,26 +18,38 @@ #define BLOCKING 1024 -#define DEFINE_ALLOCATOR(name) \ +#define DEFINE_ALLOCATOR(name, type) \ static unsigned int name##_allocs; \ -struct name *alloc_##name##_node(void) \ +void *alloc_##name##_node(void) \ { \ static int nr; \ - static struct name *block; \ + static type *block; \ + void *ret; \ \ if (!nr) { \ nr = BLOCKING; \ - block = xcalloc(BLOCKING, sizeof(struct name)); \ + block = xmalloc(BLOCKING * sizeof(type)); \ } \ nr--; \ name##_allocs++; \ - return block++; \ + ret = block++; \ + memset(ret, 0, sizeof(type)); \ + return ret; \ } -DEFINE_ALLOCATOR(blob) -DEFINE_ALLOCATOR(tree) -DEFINE_ALLOCATOR(commit) -DEFINE_ALLOCATOR(tag) +union any_object { + struct object object; + struct blob blob; + struct tree tree; + struct commit commit; + struct tag tag; +}; + +DEFINE_ALLOCATOR(blob, struct blob) +DEFINE_ALLOCATOR(tree, struct tree) +DEFINE_ALLOCATOR(commit, struct commit) +DEFINE_ALLOCATOR(tag, struct tag) +DEFINE_ALLOCATOR(object, union any_object) #ifdef NO_C99_FORMAT #define SZ_FMT "%u"