(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

This commit is contained in:
Charles Kerr 2010-02-15 16:44:02 +00:00
parent f5c5db18da
commit bdae614636
1 changed files with 2 additions and 2 deletions

View File

@ -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 );
}