Skip to content

Commit cdf2241

Browse files
newrengitster
authored andcommitted
merge-ort: add pool_alloc, pool_calloc, and pool_strndup wrappers
Make the code more flexible so that it can handle both being run with or without a memory pool by adding utility functions which will either call xmalloc, xcalloc, xstrndup or mem_pool_alloc, mem_pool_calloc, mem_pool_strndup depending on whether we have a non-NULL memory pool. A subsequent commit will make use of these. (We will actually be dropping these functions soon and just assuming we always have a memory pool, but the flexibility was very useful during development of merge-ort so I want to be able to restore it if needed.) Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa0e936 commit cdf2241

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

merge-ort.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,30 @@ static void path_msg(struct merge_options *opt,
664664
strbuf_addch(sb, '\n');
665665
}
666666

667+
MAYBE_UNUSED
668+
static void *pool_calloc(struct mem_pool *pool, size_t count, size_t size)
669+
{
670+
if (!pool)
671+
return xcalloc(count, size);
672+
return mem_pool_calloc(pool, count, size);
673+
}
674+
675+
MAYBE_UNUSED
676+
static void *pool_alloc(struct mem_pool *pool, size_t size)
677+
{
678+
if (!pool)
679+
return xmalloc(size);
680+
return mem_pool_alloc(pool, size);
681+
}
682+
683+
MAYBE_UNUSED
684+
static void *pool_strndup(struct mem_pool *pool, const char *str, size_t len)
685+
{
686+
if (!pool)
687+
return xstrndup(str, len);
688+
return mem_pool_strndup(pool, str, len);
689+
}
690+
667691
/* add a string to a strbuf, but converting "/" to "_" */
668692
static void add_flattened_path(struct strbuf *out, const char *s)
669693
{

0 commit comments

Comments
 (0)