diff options
| -rw-r--r-- | src/utils.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/utils.c b/src/utils.c index 475a921..245894e 100644 --- a/src/utils.c +++ b/src/utils.c | |||
| @@ -71,11 +71,13 @@ void fdlist_reset(struct fdlist *list) | |||
| 71 | list->count = 0; | 71 | list->count = 0; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | #define CAPACITY_STEP 8 | ||
| 75 | |||
| 74 | void collection_init(struct collection *col) | 76 | void collection_init(struct collection *col) |
| 75 | { | 77 | { |
| 76 | col->list = malloc(sizeof(void *)); | 78 | col->list = malloc(sizeof(void *) * CAPACITY_STEP); |
| 77 | memset(col->list, 0, sizeof(void *)); | 79 | memset(col->list, 0, sizeof(void *) * CAPACITY_STEP); |
| 78 | col->capacity = 1; | 80 | col->capacity = CAPACITY_STEP; |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | void collection_free(struct collection *col) | 83 | void collection_free(struct collection *col) |
| @@ -94,10 +96,10 @@ void collection_add(struct collection *col, void *element) | |||
| 94 | return; | 96 | return; |
| 95 | } | 97 | } |
| 96 | } | 98 | } |
| 97 | col->list = realloc(col->list, sizeof(void*) * col->capacity * 2); | 99 | col->list = realloc(col->list, sizeof(void*) * (col->capacity + CAPACITY_STEP)); |
| 98 | memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity); | 100 | memset(&col->list[col->capacity], 0, sizeof(void *) * CAPACITY_STEP); |
| 99 | col->list[col->capacity] = element; | 101 | col->list[col->capacity] = element; |
| 100 | col->capacity *= 2; | 102 | col->capacity += CAPACITY_STEP; |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | void collection_remove(struct collection *col, void *element) | 105 | void collection_remove(struct collection *col, void *element) |
