(libT) a small, simple memory optimization

This commit is contained in:
Charles Kerr 2008-10-25 02:15:37 +00:00
parent 6b4170e970
commit 9cb73f8335
2 changed files with 31 additions and 35 deletions

View File

@ -33,8 +33,8 @@ tr_ptrArrayNew( void )
p = tr_new( tr_ptrArray, 1 ); p = tr_new( tr_ptrArray, 1 );
p->n_items = 0; p->n_items = 0;
p->n_alloc = GROW; p->n_alloc = 0;
p->items = tr_new( void*, p->n_alloc ); p->items = NULL;
return p; return p;
} }
@ -58,7 +58,7 @@ tr_ptrArrayForeach( tr_ptrArray * t,
int i; int i;
assert( t ); assert( t );
assert( t->items ); assert( t->items || !t->n_items );
assert( func ); assert( func );
for( i = 0; i < t->n_items; ++i ) for( i = 0; i < t->n_items; ++i )
@ -70,7 +70,7 @@ tr_ptrArrayFree( tr_ptrArray * t,
PtrArrayForeachFunc func ) PtrArrayForeachFunc func )
{ {
assert( t ); assert( t );
assert( t->items ); assert( t->items || !t->n_items );
if( func ) if( func )
tr_ptrArrayForeach( t, func ); tr_ptrArrayForeach( t, func );

View File

@ -40,32 +40,31 @@ void tr_ptrArrayForeach(
tr_ptrArray*, tr_ptrArray*,
PtrArrayForeachFunc func ); PtrArrayForeachFunc func );
void tr_ptrArrayFree( void tr_ptrArrayFree( tr_ptrArray * array,
tr_ptrArray*,
PtrArrayForeachFunc func ); PtrArrayForeachFunc func );
void* tr_ptrArrayNth( tr_ptrArray*, void* tr_ptrArrayNth( tr_ptrArray * array,
int n ); int nth );
void* tr_ptrArrayBack( tr_ptrArray* ); void* tr_ptrArrayBack( tr_ptrArray * array );
void** tr_ptrArrayPeek( tr_ptrArray*, void** tr_ptrArrayPeek( tr_ptrArray * array,
int * size ); int * size );
void** tr_ptrArrayBase( tr_ptrArray* ); void** tr_ptrArrayBase( tr_ptrArray * array );
void tr_ptrArrayClear( tr_ptrArray* ); void tr_ptrArrayClear( tr_ptrArray * array );
int tr_ptrArrayInsert( tr_ptrArray*, int tr_ptrArrayInsert( tr_ptrArray * array,
void*, void * insertMe,
int pos ); int pos );
int tr_ptrArrayAppend( tr_ptrArray*, int tr_ptrArrayAppend( tr_ptrArray * array,
void* ); void * appendMe );
void* tr_ptrArrayPop( tr_ptrArray* ); void* tr_ptrArrayPop( tr_ptrArray * array );
void tr_ptrArrayErase( tr_ptrArray*, void tr_ptrArrayErase( tr_ptrArray * array,
int begin, int begin,
int end ); int end );
@ -73,19 +72,16 @@ int tr_ptrArraySize( const tr_ptrArray* );
int tr_ptrArrayEmpty( const tr_ptrArray* ); int tr_ptrArrayEmpty( const tr_ptrArray* );
int tr_ptrArrayInsertSorted( tr_ptrArray*, int tr_ptrArrayInsertSorted( tr_ptrArray * array,
void*, void * value,
int compare(const void*, int compare(const void*, const void*) );
const void*) );
void* tr_ptrArrayRemoveSorted( tr_ptrArray*, void* tr_ptrArrayRemoveSorted( tr_ptrArray * array,
void*, void * value,
int compare(const void*, int compare(const void*, const void*) );
const void*) );
void* tr_ptrArrayFindSorted( tr_ptrArray*, void* tr_ptrArrayFindSorted( tr_ptrArray * array,
const void*, const void * key,
int compare(const void*, int compare(const void*, const void*) );
const void*) );
#endif #endif