diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-03-30 22:59:00 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-03-30 22:59:00 +0000 |
commit | 93ab51e9ac6173d3aebde2df1393ee2ee7f6a28e (patch) | |
tree | 7fc72f4ce789e840f04b8632d5b5799b31cb26b5 /src/common/util.c | |
parent | 2d3ac08633a47617c1244caab8b41f73604e0d48 (diff) | |
download | tor-93ab51e9ac6173d3aebde2df1393ee2ee7f6a28e.tar.gz tor-93ab51e9ac6173d3aebde2df1393ee2ee7f6a28e.zip |
Make smartlist Do What Arma Expects.
svn:r1401
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 9 |
1 files changed, 5 insertions, 4 deletions
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); } |