Skip to content

Commit 69f6dea

Browse files
peffgitster
authored andcommitted
combine-diff: drop public declaration of combine_diff_path_size()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b20d7d3 commit 69f6dea

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

combine-diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,16 +1658,17 @@ struct combine_diff_path *combine_diff_path_new(const char *path,
16581658
size_t num_parents)
16591659
{
16601660
struct combine_diff_path *p;
1661+
size_t parent_len = st_mult(sizeof(p->parent[0]), num_parents);
16611662

1662-
p = xmalloc(combine_diff_path_size(num_parents, path_len));
1663+
p = xmalloc(st_add4(sizeof(*p), path_len, 1, parent_len));
16631664
p->path = (char *)&(p->parent[num_parents]);
16641665
memcpy(p->path, path, path_len);
16651666
p->path[path_len] = 0;
16661667
p->next = NULL;
16671668
p->mode = mode;
16681669
oidcpy(&p->oid, oid);
16691670

1670-
memset(p->parent, 0, sizeof(p->parent[0]) * num_parents);
1671+
memset(p->parent, 0, parent_len);
16711672

16721673
return p;
16731674
}

diff.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,6 @@ struct combine_diff_path {
489489
char *path;
490490
} parent[FLEX_ARRAY];
491491
};
492-
#define combine_diff_path_size(n, l) \
493-
st_add4(sizeof(struct combine_diff_path), (l), 1, \
494-
st_mult(sizeof(struct combine_diff_parent), (n)))
495492
struct combine_diff_path *combine_diff_path_new(const char *path,
496493
size_t path_len,
497494
unsigned int mode,

0 commit comments

Comments
 (0)