summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-21 17:41:40 -0700
committerJunio C Hamano <junkio@cox.net>2007-04-21 17:42:02 -0700
commit42c4b58059fa9af65e90f2c418bb551e30d1d32f (patch)
treec6aa1b75909009b249ceb768717c27011b73adb4 /alloc.c
parent520635fa3a7781cce412f6b02e165b5d897a99d1 (diff)
parent100c5f3b0b27ec6617de1a785c4ff481e92636c1 (diff)
downloadgit-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.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/alloc.c b/alloc.c
index 460db192d5..216c23a6f8 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"