summaryrefslogtreecommitdiffstats
path: root/mem-pool.h
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2024-02-25 12:39:44 +0100
committerJunio C Hamano <gitster@pobox.com>2024-02-26 18:35:40 +0100
commit8d25663d704d1216d2fd5db5fd3aa431b8c58268 (patch)
tree384ea573a038437501a38a4a6195ae52d21ef4ea /mem-pool.h
parentGit 2.44 (diff)
downloadgit-8d25663d704d1216d2fd5db5fd3aa431b8c58268.tar.xz
git-8d25663d704d1216d2fd5db5fd3aa431b8c58268.zip
mem-pool: add mem_pool_strfmt()
Add a function for building a string, printf style, using a memory pool. It uses the free space in the current block in the first attempt. If that suffices then the result can already be used without copying or reformatting. For strings that are significantly shorter on average than the block size (ca. 1 MiB by default) this is the case most of the time, leading to a better perfomance than a solution that doesn't access mem-pool internals. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'mem-pool.h')
-rw-r--r--mem-pool.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/mem-pool.h b/mem-pool.h
index fe7507f022..d1c66413ec 100644
--- a/mem-pool.h
+++ b/mem-pool.h
@@ -48,6 +48,11 @@ char *mem_pool_strdup(struct mem_pool *pool, const char *str);
char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len);
/*
+ * Allocate memory from the memory pool and format a string into it.
+ */
+char *mem_pool_strfmt(struct mem_pool *pool, const char *fmt, ...);
+
+/*
* Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
* pool will be empty and not contain any memory. It still needs to be free'd
* with a call to `mem_pool_discard`.