aboutsummaryrefslogtreecommitdiffstats
path: root/xdiff/xutils.h
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-07-08 16:25:19 +0000
committerJunio C Hamano <gitster@pobox.com>2022-07-08 09:34:30 -0700
commitf7b587bf656574103a0a2ad9c2337b0d15c0e92d (patch)
tree00bc34a5d6773022acd2a3a9434d50b7a9dc073a /xdiff/xutils.h
parent848fd5ae5b6506df50ae872302d94b794dc57d51 (diff)
downloadgit-f7b587bf656574103a0a2ad9c2337b0d15c0e92d.tar.gz
xdiff: introduce XDL_ALLOC_GROW()
Add a helper to grow an array. This is analogous to ALLOC_GROW() in the rest of the codebase but returns −1 on allocation failure to accommodate other users of libxdiff such as libgit2. It will also return a error if the multiplication overflows while calculating the new allocation size. Note that this keeps doubling on reallocation like the code it is replacing rather than increasing the existing size by half like ALLOC_GROW(). It does however copy ALLOC_GROW()'s trick of adding a small amount to the new allocation to avoid a lot of reallocations at small sizes. Note that xdl_alloc_grow_helper() uses long rather than size_t for `nr` and `alloc` to match the existing code. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xutils.h')
-rw-r--r--xdiff/xutils.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/xdiff/xutils.h b/xdiff/xutils.h
index fba7bae03c..fd0bba94e8 100644
--- a/xdiff/xutils.h
+++ b/xdiff/xutils.h
@@ -42,6 +42,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
int line1, int count1, int line2, int count2);
-
+/* Do not call this function, use XDL_ALLOC_GROW instead */
+void* xdl_alloc_grow_helper(void* p, long nr, long* alloc, size_t size);
#endif /* #if !defined(XUTILS_H) */