From bdae6146363b682d77204941cbd27070428a1705 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 15 Feb 2010 16:44:02 +0000 Subject: [PATCH] (trunk libT) instead of growing the ptrArray by a constant fixed amount when it runs out of room, follow exponential growth to minimize the number of realloc()s needed. This speeds up populating large arrays in bencode.c --- libtransmission/ptrarray.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libtransmission/ptrarray.c b/libtransmission/ptrarray.c index a4b07bf9c..418edd962 100644 --- a/libtransmission/ptrarray.c +++ b/libtransmission/ptrarray.c @@ -17,7 +17,7 @@ #include "ptrarray.h" #include "utils.h" -#define GROW 32 +#define FLOOR 32 const tr_ptrArray TR_PTR_ARRAY_INIT = { NULL, 0, 0 }; @@ -78,7 +78,7 @@ tr_ptrArrayInsert( tr_ptrArray * t, if( t->n_items >= t->n_alloc ) { - t->n_alloc = t->n_items + GROW; + t->n_alloc = MAX( FLOOR, t->n_alloc * 2 ); t->items = tr_renew( void*, t->items, t->n_alloc ); }