From 93ab51e9ac6173d3aebde2df1393ee2ee7f6a28e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Mar 2004 22:59:00 +0000 Subject: Make smartlist Do What Arma Expects. svn:r1401 --- src/common/util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/common/util.c') diff --git a/src/common/util.c b/src/common/util.c index 069e879d00..2a688316b6 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -117,10 +117,11 @@ void set_uint32(char *cp, uint32_t v) * _add() adds an element, _remove() removes an element if it's there, * _choose() returns a random element. */ -smartlist_t *smartlist_create(int capacity) { +#define SMARTLIST_DEFAULT_CAPACITY 32 +smartlist_t *smartlist_create() { smartlist_t *sl = tor_malloc(sizeof(smartlist_t)); sl->num_used = 0; - sl->capacity = capacity; + sl->capacity = SMARTLIST_DEFAULT_CAPACITY; sl->list = tor_malloc(sizeof(void *) * sl->capacity); return sl; } @@ -130,8 +131,8 @@ void smartlist_free(smartlist_t *sl) { free(sl); } -void smartlist_grow_capacity(smartlist_t *sl, int n) { - if (sl->capacity < n) { +void smartlist_set_capacity(smartlist_t *sl, int n) { + if (sl->capacity != n && sl->num_used < n) { sl->capacity = n; sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity); } -- cgit v1.2.3-54-g00ecf