use CALLOC_ARRAY

Add and apply a semantic patch for converting code that open-codes
CALLOC_ARRAY to use it instead.  It shortens the code and infers the
element size automatically.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2021-03-13 17:17:22 +01:00
committed by Junio C Hamano
parent f1121499e6
commit ca56dadb4b
88 changed files with 190 additions and 188 deletions

View File

@ -303,7 +303,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
return;
}
ci = xcalloc(1, sizeof(struct rename_conflict_info));
CALLOC_ARRAY(ci, 1);
ci->rename_type = rename_type;
ci->ren1 = ren1;
ci->ren2 = ren2;
@ -2389,8 +2389,7 @@ static void compute_collisions(struct hashmap *collisions,
continue;
collision_ent = collision_find_entry(collisions, new_path);
if (!collision_ent) {
collision_ent = xcalloc(1,
sizeof(struct collision_entry));
CALLOC_ARRAY(collision_ent, 1);
hashmap_entry_init(&collision_ent->ent,
strhash(new_path));
hashmap_put(collisions, &collision_ent->ent);
@ -2594,7 +2593,7 @@ static struct string_list *get_renames(struct merge_options *opt,
struct string_list *renames;
compute_collisions(&collisions, dir_renames, pairs);
renames = xcalloc(1, sizeof(struct string_list));
CALLOC_ARRAY(renames, 1);
for (i = 0; i < pairs->nr; ++i) {
struct string_list_item *item;
@ -3664,7 +3663,7 @@ static int merge_start(struct merge_options *opt, struct tree *head)
return -1;
}
opt->priv = xcalloc(1, sizeof(*opt->priv));
CALLOC_ARRAY(opt->priv, 1);
string_list_init(&opt->priv->df_conflict_file_set, 1);
return 0;
}