@matheusbsbs / matheus-bagliano / commits / 7a2bff4593
Fork 0

Replace custom memory growth allocator with ALLOC_GROW

The ALLOC_GROW macro is a shorter way to implement an array that grows upon demand as additional items are added to it. We have mostly standardized upon its use within git and transport.c is not an exception. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Sep 14, 2007 at 03:31 UTC 7a2bff45937a60d846abf3ccb42015539aedcb40
1 file changed +3 -8
transport.c
+3 -8
@@ -474,13 +474,11 @@ struct ref *transport_get_remote_refs(struct transport *transport)
474 return transport->remote_refs;
475 }
476
477 -#define PACK_HEADS_CHUNK_COUNT 256
478 -
477 int transport_fetch_refs(struct transport *transport, struct ref *refs)
478 {
479 int i;
482 - int nr_heads = 0;
483 - char **heads = xmalloc(PACK_HEADS_CHUNK_COUNT * sizeof(char *));
480 + int nr_heads = 0, nr_alloc = 0;
481 + char **heads = NULL;
482 struct ref *rm;
483 int use_objs = !transport->ops->fetch_refs;
484
@@ -488,15 +486,12 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
486 if (rm->peer_ref &&
487 !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
488 continue;
489 + ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
490 if (use_objs) {
491 heads[nr_heads++] = xstrdup(sha1_to_hex(rm->old_sha1));
492 } else {
493 heads[nr_heads++] = xstrdup(rm->name);
494 }
496 - if (nr_heads % PACK_HEADS_CHUNK_COUNT == 0)
497 - heads = xrealloc(heads,
498 - (nr_heads + PACK_HEADS_CHUNK_COUNT) *
499 - sizeof(char *));
495 }
496
497 if (use_objs) {