threads / patch / 60657

patchfast-import: use mem_pool_calloc()

Subject: [PATCH] fast-import: use mem_pool_calloc()

## tl;dr

2 messages between Dec 26, 2023 and Dec 26, 2023. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Dec 26, 2023, 08:17 UTC · lore

Use mem_pool_calloc() to get a zeroed buffer instead of zeroing it ourselves. This makes the code clearer and less repetitive.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/fast-import.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to builtin/fast-import.c +1 −3
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 444f41cf8c..92eda20683 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2809,8 +2809,7 @@ static void parse_new_tag(const char *arg)
 	enum object_type type;
 	const char *v;

-	t = mem_pool_alloc(&fi_mem_pool, sizeof(struct tag));
-	memset(t, 0, sizeof(struct tag));
+	t = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct tag));
 	t->name = mem_pool_strdup(&fi_mem_pool, arg);
 	if (last_tag)
 		last_tag->next_tag = t;
--
2.43.0
Elijah Newren· Dec 26, 2023, 19:22 UTC · re: René Scharfe · lore

Re: [PATCH] fast-import: use mem_pool_calloc()

On Tue, Dec 26, 2023 at 12:18 AM René Scharfe <l.s.r@web.de> wrote:
Show 25 quoted lines
>
> Use mem_pool_calloc() to get a zeroed buffer instead of zeroing it
> ourselves.  This makes the code clearer and less repetitive.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  builtin/fast-import.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 444f41cf8c..92eda20683 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -2809,8 +2809,7 @@ static void parse_new_tag(const char *arg)
>         enum object_type type;
>         const char *v;
>
> -       t = mem_pool_alloc(&fi_mem_pool, sizeof(struct tag));
> -       memset(t, 0, sizeof(struct tag));
> +       t = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct tag));
>         t->name = mem_pool_strdup(&fi_mem_pool, arg);
>         if (last_tag)
>                 last_tag->next_tag = t;
> --
> 2.43.0
Makes sense; looks good to me.

← back to recent threads