# [PATCH] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.

5 messages from 2010-12-14 to 2010-12-19. Participants: Thiago Farina, Nguyen Thai Ngoc Duy.
Thread: https://gitlist.dev/t/26046

## Thiago Farina, 2010-12-14 01:48

Subject: [PATCH] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <ffd7b63f3ef5e409775a0d730691efdaf4e41592.1292291262.git.tfransosi@gmail.com>
URL: https://gitlist.dev/e/ffd7b63f3ef5e409775a0d730691efdaf4e41592.1292291262.git.tfransosi%40gmail.com

```
Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
 builtin/rm.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index c7b7bb3..faeedfc 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -22,10 +22,7 @@ static struct {
 
 static void add_list(const char *name)
 {
-	if (list.nr >= list.alloc) {
-		list.alloc = alloc_nr(list.alloc);
-		list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
-	}
+	ALLOC_GROW(list.name, list.nr + 1, list.alloc);
 	list.name[list.nr++] = name;
 }
 
-- 
1.7.3.2.343.g7d43d

```

## Thiago Farina, 2010-12-18 23:03

Subject: Re: [PATCH] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <AANLkTimLy0uE980GFfaVJt19XuhZDO2OLRbEgs=oyY=2@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimLy0uE980GFfaVJt19XuhZDO2OLRbEgs%3DoyY%3D2%40mail.gmail.com
In-Reply-To: <ffd7b63f3ef5e409775a0d730691efdaf4e41592.1292291262.git.tfransosi@gmail.com>

```
On Mon, Dec 13, 2010 at 11:48 PM, Thiago Farina <tfransosi@gmail.com> wrote:
> Signed-off-by: Thiago Farina <tfransosi@gmail.com>
> ---
>  builtin/rm.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/rm.c b/builtin/rm.c
> index c7b7bb3..faeedfc 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -22,10 +22,7 @@ static struct {
>
>  static void add_list(const char *name)
>  {
> -       if (list.nr >= list.alloc) {
> -               list.alloc = alloc_nr(list.alloc);
> -               list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
> -       }
> +       ALLOC_GROW(list.name, list.nr + 1, list.alloc);
>        list.name[list.nr++] = name;
>  }
>

+Jonathan, he might Ack this.

```

## Nguyen Thai Ngoc Duy, 2010-12-19 03:02

Subject: Re: [PATCH] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <AANLkTim4GE0mnCBqz6QubpL6g9Bz5U-jHoOw=_MR5-1j@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim4GE0mnCBqz6QubpL6g9Bz5U-jHoOw%3D_MR5-1j%40mail.gmail.com
In-Reply-To: <ffd7b63f3ef5e409775a0d730691efdaf4e41592.1292291262.git.tfransosi@gmail.com>

```
On Tue, Dec 14, 2010 at 8:48 AM, Thiago Farina <tfransosi@gmail.com> wrote:
>  static void add_list(const char *name)
>  {
> -       if (list.nr >= list.alloc) {
> -               list.alloc = alloc_nr(list.alloc);
> -               list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
> -       }
> +       ALLOC_GROW(list.name, list.nr + 1, list.alloc);
>        list.name[list.nr++] = name;
>  }

add_list() is only used at one place, why not remove it and put the
code back in cmd_rm()?
-- 
Duy

```

## Thiago Farina, 2010-12-19 11:56

Subject: [PATCH v2] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <97af5e0255d234e3a7ec5df1e387bec39ed94206.1292759580.git.tfransosi@gmail.com>
URL: https://gitlist.dev/e/97af5e0255d234e3a7ec5df1e387bec39ed94206.1292759580.git.tfransosi%40gmail.com
In-Reply-To: <AANLkTim4GE0mnCBqz6QubpL6g9Bz5U-jHoOw=_MR5-1j@mail.gmail.com>

```
Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
 Changes from v1:
 - Remove the add_list function since it's used only once per Nguyen Thai Ngoc Duy
   review.

 builtin/rm.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index c7b7bb3..ff491d7 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -20,15 +20,6 @@ static struct {
 	const char **name;
 } list;
 
-static void add_list(const char *name)
-{
-	if (list.nr >= list.alloc) {
-		list.alloc = alloc_nr(list.alloc);
-		list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
-	}
-	list.name[list.nr++] = name;
-}
-
 static int check_local_mod(unsigned char *head, int index_only)
 {
 	/*
@@ -182,7 +173,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 		struct cache_entry *ce = active_cache[i];
 		if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
 			continue;
-		add_list(ce->name);
+		ALLOC_GROW(list.name, list.nr + 1, list.alloc);
+		list.name[list.nr++] = ce->name;
 	}
 
 	if (pathspec) {
-- 
1.7.3.2.343.g7d43d

```

## Thiago Farina, 2010-12-19 11:58

Subject: Re: [PATCH v2] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <AANLkTim-zv6WZZ_DErnoNBhgJw3DnC0jHSH-Mg2CzkhV@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim-zv6WZZ_DErnoNBhgJw3DnC0jHSH-Mg2CzkhV%40mail.gmail.com
In-Reply-To: <97af5e0255d234e3a7ec5df1e387bec39ed94206.1292759580.git.tfransosi@gmail.com>

```
Forgot to copy Jonathan when using 'git send-email'. Now copying him.

On Sun, Dec 19, 2010 at 9:56 AM, Thiago Farina <tfransosi@gmail.com> wrote:
> Signed-off-by: Thiago Farina <tfransosi@gmail.com>
> ---
>  Changes from v1:
>  - Remove the add_list function since it's used only once per Nguyen Thai Ngoc Duy
>   review.
>
>  builtin/rm.c |   12 ++----------
>  1 files changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/builtin/rm.c b/builtin/rm.c
> index c7b7bb3..ff491d7 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -20,15 +20,6 @@ static struct {
>        const char **name;
>  } list;
>
> -static void add_list(const char *name)
> -{
> -       if (list.nr >= list.alloc) {
> -               list.alloc = alloc_nr(list.alloc);
> -               list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
> -       }
> -       list.name[list.nr++] = name;
> -}
> -
>  static int check_local_mod(unsigned char *head, int index_only)
>  {
>        /*
> @@ -182,7 +173,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>                struct cache_entry *ce = active_cache[i];
>                if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
>                        continue;
> -               add_list(ce->name);
> +               ALLOC_GROW(list.name, list.nr + 1, list.alloc);
> +               list.name[list.nr++] = ce->name;
>        }
>
>        if (pathspec) {
> --
> 1.7.3.2.343.g7d43d
>
>

```
