Skip to content

Commit 5447a76

Browse files
rscharfegitster
authored andcommitted
commit: use FLEX_ARRAY in struct merge_remote_desc
Convert the name member of struct merge_remote_desc to a FLEX_ARRAY and use FLEX_ALLOC_STR to build the struct. This halves the number of memory allocations, saves the storage for a pointer and avoids an indirection when reading the name. Suggested-by: Jeff King <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a257165 commit 5447a76

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,8 @@ void set_merge_remote_desc(struct commit *commit,
15801580
const char *name, struct object *obj)
15811581
{
15821582
struct merge_remote_desc *desc;
1583-
desc = xmalloc(sizeof(*desc));
1583+
FLEX_ALLOC_STR(desc, name, name);
15841584
desc->obj = obj;
1585-
desc->name = xstrdup(name);
15861585
commit->util = desc;
15871586
}
15881587

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ extern void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *
356356

357357
struct merge_remote_desc {
358358
struct object *obj; /* the named object, could be a tag */
359-
const char *name;
359+
char name[FLEX_ARRAY];
360360
};
361361
#define merge_remote_util(commit) ((struct merge_remote_desc *)((commit)->util))
362362
extern void set_merge_remote_desc(struct commit *commit,

0 commit comments

Comments
 (0)