summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c9
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);
}