Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 52604d7

Browse files
peffgitster
authored andcommitted
alloc: write out allocator definitions
Because the allocator functions for tree, blobs, etc are all very similar, we originally used a macro to avoid repeating ourselves. Since the prior commit, though, the heavy lifting is done by an inline helper function. The macro does still save us a few lines, but at some readability cost. It obfuscates the function definitions (and makes them hard to find via grep). Much worse, though, is the fact that it isn't used consistently for all allocators. Somebody coming later may be tempted to modify DEFINE_ALLOCATOR, but they would miss alloc_commit_node, which is treated specially. Let's just drop the macro and write everything out explicitly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c3f3f2 commit 52604d7

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

alloc.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818

1919
#define BLOCKING 1024
2020

21-
#define DEFINE_ALLOCATOR(name, type) \
22-
static struct alloc_state name##_state; \
23-
void *alloc_##name##_node(void) \
24-
{ \
25-
return alloc_node(&name##_state, sizeof(type)); \
26-
}
27-
2821
union any_object {
2922
struct object object;
3023
struct blob blob;
@@ -55,10 +48,33 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
5548
return ret;
5649
}
5750

58-
DEFINE_ALLOCATOR(blob, struct blob)
59-
DEFINE_ALLOCATOR(tree, struct tree)
60-
DEFINE_ALLOCATOR(tag, struct tag)
61-
DEFINE_ALLOCATOR(object, union any_object)
51+
static struct alloc_state blob_state;
52+
void *alloc_blob_node(void)
53+
{
54+
struct blob *b = alloc_node(&blob_state, sizeof(struct blob));
55+
return b;
56+
}
57+
58+
static struct alloc_state tree_state;
59+
void *alloc_tree_node(void)
60+
{
61+
struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
62+
return t;
63+
}
64+
65+
static struct alloc_state tag_state;
66+
void *alloc_tag_node(void)
67+
{
68+
struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
69+
return t;
70+
}
71+
72+
static struct alloc_state object_state;
73+
void *alloc_object_node(void)
74+
{
75+
struct object *obj = alloc_node(&object_state, sizeof(union any_object));
76+
return obj;
77+
}
6278

6379
static struct alloc_state commit_state;
6480

0 commit comments

Comments
 (0)