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 <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 13, 2016 at 14:21 UTC
5447a76aad4074c31e7c8a6299cc586435f385e9
2 files changed
+2
-3
commit.c
+1
-2
@@ -1580,9 +1580,8 @@ void set_merge_remote_desc(struct commit *commit,
1580
const char *name, struct object *obj)
1581
{
1582
struct merge_remote_desc *desc;
1583
- desc = xmalloc(sizeof(*desc));
1583
+ FLEX_ALLOC_STR(desc, name, name);
1584
desc->obj = obj;
1585
- desc->name = xstrdup(name);
1585
commit->util = desc;
1586
}
1587
commit.h
+1
-1
@@ -356,7 +356,7 @@ extern void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *
356
357
struct merge_remote_desc {
358
struct object *obj; /* the named object, could be a tag */
359
- const char *name;
359
+ char name[FLEX_ARRAY];
360
};
361
#define merge_remote_util(commit) ((struct merge_remote_desc *)((commit)->util))
362
extern void set_merge_remote_desc(struct commit *commit,