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>
This commit is contained in:
parent
c4ad00f8cc
commit
5de7f500c1
9
alloc.c
9
alloc.c
@ -82,12 +82,17 @@ void *alloc_object_node(void)
|
|||||||
|
|
||||||
static struct alloc_state commit_state;
|
static struct alloc_state commit_state;
|
||||||
|
|
||||||
|
unsigned int alloc_commit_index(void)
|
||||||
|
{
|
||||||
|
static unsigned int count;
|
||||||
|
return count++;
|
||||||
|
}
|
||||||
|
|
||||||
void *alloc_commit_node(void)
|
void *alloc_commit_node(void)
|
||||||
{
|
{
|
||||||
static int commit_count;
|
|
||||||
struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
|
struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
|
||||||
c->object.type = OBJ_COMMIT;
|
c->object.type = OBJ_COMMIT;
|
||||||
c->index = commit_count++;
|
c->index = alloc_commit_index();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
cache.h
1
cache.h
@ -1354,6 +1354,7 @@ extern void *alloc_commit_node(void);
|
|||||||
extern void *alloc_tag_node(void);
|
extern void *alloc_tag_node(void);
|
||||||
extern void *alloc_object_node(void);
|
extern void *alloc_object_node(void);
|
||||||
extern void alloc_report(void);
|
extern void alloc_report(void);
|
||||||
|
extern unsigned int alloc_commit_index(void);
|
||||||
|
|
||||||
/* trace.c */
|
/* trace.c */
|
||||||
__attribute__((format (printf, 1, 2)))
|
__attribute__((format (printf, 1, 2)))
|
||||||
|
Loading…
Reference in New Issue
Block a user