diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-03-30 20:05:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-03-30 20:05:52 +0000 |
commit | 96a86ef14d8b4f2377e19070ae930de730efd2f8 (patch) | |
tree | 779bf8db11c9b31a250d86880c161916450087a1 /src/common | |
parent | 0ba9ab5fb05ceb064a24e2db91e7a2f72cea2722 (diff) | |
download | tor-96a86ef14d8b4f2377e19070ae930de730efd2f8.tar tor-96a86ef14d8b4f2377e19070ae930de730efd2f8.tar.gz |
Remove maximum-size field from smartlists
svn:r1397
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 23 | ||||
-rw-r--r-- | src/common/util.h | 3 |
2 files changed, 8 insertions, 18 deletions
diff --git a/src/common/util.c b/src/common/util.c index 7afc854e0..069e879d0 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -117,16 +117,10 @@ 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. */ -#define SL_DEFAULT_CAPACITY 32 - -smartlist_t *smartlist_create(int max_elements) { +smartlist_t *smartlist_create(int capacity) { smartlist_t *sl = tor_malloc(sizeof(smartlist_t)); sl->num_used = 0; - sl->max = max_elements; - if (max_elements <= SL_DEFAULT_CAPACITY) - sl->capacity = max_elements; - else - sl->capacity = SL_DEFAULT_CAPACITY; + sl->capacity = capacity; sl->list = tor_malloc(sizeof(void *) * sl->capacity); return sl; } @@ -145,14 +139,11 @@ void smartlist_grow_capacity(smartlist_t *sl, int n) { /* add element to the list, but only if there's room */ void smartlist_add(smartlist_t *sl, void *element) { - if (sl->num_used < sl->max) { - if (sl->num_used >= sl->capacity) { - sl->capacity *= 2; - sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity); - } - sl->list[sl->num_used++] = element; - } else - log_fn(LOG_WARN,"We've already got %d elements, discarding.",sl->max); + if (sl->num_used >= sl->capacity) { + sl->capacity *= 2; + sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity); + } + sl->list[sl->num_used++] = element; } void smartlist_remove(smartlist_t *sl, void *element) { diff --git a/src/common/util.h b/src/common/util.h index 3907a0d94..9465a8f78 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -61,11 +61,10 @@ void set_uint32(char *cp, uint32_t v); typedef struct { void **list; int num_used; - int max; int capacity; } smartlist_t; -smartlist_t *smartlist_create(int max_elements); +smartlist_t *smartlist_create(int capacity); void smartlist_free(smartlist_t *sl); void smartlist_grow_capacity(smartlist_t *sl, int n); void smartlist_add(smartlist_t *sl, void *element); |