From 2c1cbec1e2f0bd7b15fe5e921d287babfd91c7d3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 16 Apr 2007 22:10:19 -0700 Subject: Use proper object allocators for unknown object nodes too We used to use a different allocator scheme for when we didn't know the object type. That meant that objects that were created without any up-front knowledge of the type would not go through the same allocation paths as normal object allocations, and would miss out on the statistics. But perhaps more importantly than the statistics (that are useful when looking at memory usage but not much else), if we want to make the object hash tables use a denser object pointer representation, we need to make sure that they all go through the same blocking allocator. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- alloc.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'alloc.c') diff --git a/alloc.c b/alloc.c index 460db192d5..53eba373db 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) \ { \ 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" -- cgit v1.2.3