--- libaitio/src/Attic/array.c 2011/08/29 12:00:57 1.4 +++ libaitio/src/Attic/array.c 2011/08/31 12:29:32 1.4.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.4 2011/08/29 12:00:57 misho Exp $ +* $Id: array.c,v 1.4.2.1 2011/08/31 12:29:32 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -69,7 +69,7 @@ io_arrayInit(int numItems) free(arr); return NULL; } else - memset(arr->arr_data, 0, io_arraySize(arr) * sizeof(void*)); + io_arrayZero(arr); return arr; } @@ -150,7 +150,6 @@ io_arrayFree(array_t * __restrict arr) { register int i; - assert(arr); if (!arr) return; @@ -169,7 +168,6 @@ io_arrayFree(array_t * __restrict arr) inline void io_arrayDestroy(array_t ** __restrict parr) { - assert(parr && *parr); if (!parr || !*parr) return; @@ -202,14 +200,15 @@ io_arrayLen(array_t * __restrict arr) * io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!! * @arr = Array * @newNumItems = Number of Items + * @freeShrink = Free elements before shrink array * return: -1 error, 0 ok */ int -io_arrayGrow(array_t * __restrict arr, int newNumItems) +io_arrayGrow(array_t * __restrict arr, int newNumItems, int freeShrink) { void **data; int n = 0; -/* register int i; */ + register int i; assert(arr); if (!arr) @@ -219,11 +218,10 @@ io_arrayGrow(array_t * __restrict arr, int newNumItems return 0; if (io_arraySize(arr) < newNumItems) { n = newNumItems - io_arraySize(arr); - } /* else + } else if (freeShrink) for (i = newNumItems; i < arr->arr_num; i++) if (arr->arr_data[i]) free(arr->arr_data[i]); - */ arr->arr_num = newNumItems; if (io_arraySize(arr)) { @@ -367,7 +365,7 @@ io_arrayConcat(array_t * __restrict dest, array_t * __ return -1; n = io_arraySize(dest); - if (io_arrayGrow(dest, n + io_arraySize(src))) + if (io_arrayGrow(dest, n + io_arraySize(src), 0)) return -1; memcpy(dest->arr_data + n, src->arr_data, io_arraySize(src) * sizeof(void*));