diff options
author | Junio C Hamano <junkio@cox.net> | 2007-04-21 17:41:40 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-21 17:42:02 -0700 |
commit | 42c4b58059fa9af65e90f2c418bb551e30d1d32f (patch) | |
tree | c6aa1b75909009b249ceb768717c27011b73adb4 /alloc.c | |
parent | 520635fa3a7781cce412f6b02e165b5d897a99d1 (diff) | |
parent | 100c5f3b0b27ec6617de1a785c4ff481e92636c1 (diff) | |
download | git-42c4b58059fa9af65e90f2c418bb551e30d1d32f.tar.gz |
Merge branch 'lt/objalloc'
* 'lt/objalloc':
Clean up object creation to use more common code
Use proper object allocators for unknown object nodes too
Diffstat (limited to 'alloc.c')
-rw-r--r-- | alloc.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -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" |