Skip to content

alloc.c: remove alloc_raw_commit_node() function

Ramsay Jones git 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 6 repliesIn review
  2. v11 patch 5 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2Makefile: Add a target to generate C preprocessor output filesMakefile+3 -10 replies
1/2alloc.c: remove the alloc_raw_commit_node() functionalloc.c+29 -182 replies
2/2MSVC: Fix an "incompatible pointer types" compiler warningcompat/mingw.h compat/msvc.h+19 -250 replies
2/2alloc.c: remove the redundant commit_count variablealloc.c+1 -234 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/2] alloc.c: remove alloc_raw_commit_node() function

Hi Jeff,

Another attempt to remove this intermediate allocator. ;-)

I didn't think I would like this approach before I started to look at doing this patch, but now I think I rather like it!

The first patch uses an inline function (alloc_node()) to implement the allocators, redefining the macro to declare the allocators to, basically:

    static struct alloc_state something_state;
    void *alloc_something_node(void)
    {
    	return alloc_node(&something_state, sizeof(struct something));
    }

Then alloc_commit_node() can also use the alloc_node() function in its implementation.

I checked that the alloc_node() function was actually inlined by gcc, which it was for -O1 -> -O3 (but not for -O0, obviously). The generated assembler looked very similar (but not identical) to the code generated without this patch. Also, I did a quick (and admittedly unsophisticated) performance test. I could not detect any difference, within the noise level of the timings, between the two. (Also, operf barely registered any samples against the alloc functions, for './git log -p >/dev/null').

I also checked the assembler generated by clang, and the story was _almost_ the same. For -O2 -> -O3, clang produced very similar results to gcc. For -O1, clang didn't inline alloc_node(), but used it as a 'leaf' function; the blob allocator function 'fell into' alloc_node() and the other DEFINE-ed allocators 'jmp'-ed to alloc_node() rather than call-ing it. The alloc_commit_node() allocator did actually call alloc_node(). (probably because it was more complicated than a single return ...).

Note this was tested (on 32-bit Linux Mint 17) with gcc 4.8.2 and clang 3.4. (Other compilers probably will behave differently ...)

The second patch is just a minor clean-up and could be squashed into the first patch. (NOTE: I assume that you want c->index to start at zero; if not ...)

ATB,
Ramsay Jones

Ramsay Allan Jones (2):
alloc.c: remove the alloc_raw_commit_node() function alloc.c: remove the redundant commit_count variable

 alloc.c | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)
Signature · 1 line
2.0.0