In order to encapsulate the setting of the unique commit index, commit 969eba63 ("commit: push commit_index update into alloc_commit_node", 10-06-2014) introduced a (logically private) intermediary allocator function. However, this function (alloc_raw_commit_node()) was declared as a public function, which undermines its entire purpose.
Remove the alloc_raw_commit_node() function and inline its code into the (public) alloc_commit_node() function. Noticed by sparse ("symbol 'alloc_raw_commit_node' was not declared. Should it be static?"). Signed-off-by: Ramsay Jones <ram...@ramsay1.demon.co.uk> --- Hi Jeff, I noticed this while it was still in 'pu', but got distracted and didn't send this in time ... sorry about that! :( My first attempt at fixing this involved changing the DEFINE_ALLOCATOR macro to include a 'scope' parameter so that I could declare the raw_commit allocator 'static'. Unfortunately, I could not pass the extern keyword as the scope parameter to all the other allocators, because that made sparse even more upset - you can't use extern on a function _definition_. That meant passing an empty argument (or a comment token) to the scope parameter. This worked for gcc 4.8.2 and clang 3.4, but I was a little concerned about portability. This seems a better solution to me. Having said that ... as I'm typing this I realized that I could have removed the 'commit_count' variable and used 'commit_allocs' to set c->index instead! :-P Oh well ... ATB, Ramsay Jones alloc.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/alloc.c b/alloc.c index eb22a45..124d710 100644 --- a/alloc.c +++ b/alloc.c @@ -47,16 +47,30 @@ union any_object { DEFINE_ALLOCATOR(blob, struct blob) DEFINE_ALLOCATOR(tree, struct tree) -DEFINE_ALLOCATOR(raw_commit, struct commit) DEFINE_ALLOCATOR(tag, struct tag) DEFINE_ALLOCATOR(object, union any_object) +static unsigned int commit_allocs; + void *alloc_commit_node(void) { static int commit_count; - struct commit *c = alloc_raw_commit_node(); + static int nr; + static struct commit *block; + struct commit *c; + void *ret; + + if (!nr) { + nr = BLOCKING; + block = xmalloc(BLOCKING * sizeof(struct commit)); + } + nr--; + commit_allocs++; + ret = block++; + memset(ret, 0, sizeof(struct commit)); + c = (struct commit *) ret; c->index = commit_count++; - return c; + return ret; } static void report(const char *name, unsigned int count, size_t size) @@ -72,7 +86,7 @@ void alloc_report(void) { REPORT(blob, struct blob); REPORT(tree, struct tree); - REPORT(raw_commit, struct commit); + REPORT(commit, struct commit); REPORT(tag, struct tag); REPORT(object, union any_object); } -- 2.0.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html