]> git.ipfire.org Git - thirdparty/git.git/commitdiff
combine-diff: drop public declaration of combine_diff_path_size()
authorJeff King <peff@peff.net>
Thu, 9 Jan 2025 08:50:19 +0000 (03:50 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jan 2025 20:24:26 +0000 (12:24 -0800)
We want callers to use combine_diff_path_new() to allocate structs,
rather than using combine_diff_path_size() and xmalloc(). That gives us
more consistency over the initialization of the fields.

Now that the final external user of combine_diff_path_size() is gone, we
can stop declaring it publicly. And since our constructor is the only
caller, we can just inline it there.

Breaking the size computation into two parts also lets us reuse the
intermediate multiplication result of the parent length, since we need
to know it to perform our memset(). The result is a little easier to
read.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
combine-diff.c
diff.h

index ae3cbfc699ccc070b14e702820f0a6a34671e35d..f21e1f58ba9c461bb012aaecbb9cae2d2356838d 100644 (file)
@@ -1658,8 +1658,9 @@ struct combine_diff_path *combine_diff_path_new(const char *path,
                                                size_t num_parents)
 {
        struct combine_diff_path *p;
+       size_t parent_len = st_mult(sizeof(p->parent[0]), num_parents);
 
-       p = xmalloc(combine_diff_path_size(num_parents, path_len));
+       p = xmalloc(st_add4(sizeof(*p), path_len, 1, parent_len));
        p->path = (char *)&(p->parent[num_parents]);
        memcpy(p->path, path, path_len);
        p->path[path_len] = 0;
@@ -1667,7 +1668,7 @@ struct combine_diff_path *combine_diff_path_new(const char *path,
        p->mode = mode;
        oidcpy(&p->oid, oid);
 
-       memset(p->parent, 0, sizeof(p->parent[0]) * num_parents);
+       memset(p->parent, 0, parent_len);
 
        return p;
 }
diff --git a/diff.h b/diff.h
index 60e7db4ad6cc76efda5005ca04bc13e1ae9d7088..32ad17fd38afa401ae538336adbcc068b137f810 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -489,9 +489,6 @@ struct combine_diff_path {
                char *path;
        } parent[FLEX_ARRAY];
 };
-#define combine_diff_path_size(n, l) \
-       st_add4(sizeof(struct combine_diff_path), (l), 1, \
-               st_mult(sizeof(struct combine_diff_parent), (n)))
 struct combine_diff_path *combine_diff_path_new(const char *path,
                                                size_t path_len,
                                                unsigned int mode,