alloc: factor out commit index
We keep a static counter to set the commit index on newly allocated objects. However, since we also need to set the index on any_objects which are converted to commits, let's make the counter available as a public function. While we're moving it, let's make sure the counter is allocated as an unsigned integer to match the index field in "struct commit". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 13, 2014 at 02:42 UTC
5de7f500c13c8158696a68d86da1030313ddaf69
2 files changed
+8
-2
alloc.c
+7
-2
@@ -82,12 +82,17 @@ void *alloc_object_node(void)
82
83
static struct alloc_state commit_state;
84
85
+unsigned int alloc_commit_index(void)
86
+{
87
+ static unsigned int count;
88
+ return count++;
89
+}
90
+
91
void *alloc_commit_node(void)
92
{
87
- static int commit_count;
93
struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
94
c->object.type = OBJ_COMMIT;
90
- c->index = commit_count++;
95
+ c->index = alloc_commit_index();
96
return c;
97
}
98
cache.h
+1
@@ -1354,6 +1354,7 @@ extern void *alloc_commit_node(void);
1354
extern void *alloc_tag_node(void);
1355
extern void *alloc_object_node(void);
1356
extern void alloc_report(void);
1357
+extern unsigned int alloc_commit_index(void);
1358
1359
/* trace.c */
1360
__attribute__((format (printf, 1, 2)))