# [PATCH] attr.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.

3 messages from 2010-12-22 to 2010-12-22. Participants: Thiago Farina, Junio C Hamano.
Thread: https://gitlist.dev/t/26118

## Thiago Farina, 2010-12-22 00:35

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

```
Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
 attr.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/attr.c b/attr.c
index 6aff695..fdc0515 100644
--- a/attr.c
+++ b/attr.c
@@ -305,12 +305,8 @@ static void handle_attr_line(struct attr_stack *res,
 	a = parse_attr_line(line, src, lineno, macro_ok);
 	if (!a)
 		return;
-	if (res->alloc <= res->num_matches) {
-		res->alloc = alloc_nr(res->num_matches);
-		res->attrs = xrealloc(res->attrs,
-				      sizeof(struct match_attr *) *
-				      res->alloc);
-	}
+
+	ALLOC_GROW(res->attrs, res->num_matches + 1, res->alloc);
 	res->attrs[res->num_matches++] = a;
 }
 
-- 
1.7.3.2.343.g7d43d

```

## Junio C Hamano, 2010-12-22 00:59

Subject: Re: [PATCH] attr.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <7v1v5a7hc4.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1v5a7hc4.fsf%40alter.siamese.dyndns.org
In-Reply-To: <3c6870c390110bd1bf5c5f59a99928afc86cf188.1292978127.git.tfransosi@gmail.com>

```
Instead of trickling these down, can you give a single patch to convert
the remaining ones you have been finding with "git grep -e alloc_nr"?

```

## Thiago Farina, 2010-12-22 01:04

Subject: Re: [PATCH] attr.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.
Message-ID: <AANLkTinw-GeFp5BnBUK02_YU8=XoUw1uHprSg1Hja0sh@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinw-GeFp5BnBUK02_YU8%3DXoUw1uHprSg1Hja0sh%40mail.gmail.com
In-Reply-To: <7v1v5a7hc4.fsf@alter.siamese.dyndns.org>

```
On Tue, Dec 21, 2010 at 10:59 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Instead of trickling these down, can you give a single patch to convert
> the remaining ones you have been finding with "git grep -e alloc_nr"?
>

$ git grep -w alloc_nr | grep -v cache.h | wc -l

Sorry, but I wouldn't feel comfortable fixing 19 files now. At least
not exactly now. Perhaps on the weekend.

```
