summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-01-09 11:21:16 +0100
committerGravatar Nikias Bassen2014-01-09 11:21:16 +0100
commitbad870a5d072e5959f1adb01648dc3dbcc790b3b (patch)
treef329e9990454c740e8499887917b615cb4f6a3df /src
parent37f8ba3c2bdfe54c50d4f7f7f396c38c63a354be (diff)
downloadusbmuxd-bad870a5d072e5959f1adb01648dc3dbcc790b3b.tar.gz
usbmuxd-bad870a5d072e5959f1adb01648dc3dbcc790b3b.tar.bz2
utils: collection_add don't double capacity but instead increase by a fixed amount
Diffstat (limited to 'src')
-rw-r--r--src/utils.c14
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)
list->count = 0;
}
+#define CAPACITY_STEP 8
+
void collection_init(struct collection *col)
{
- col->list = malloc(sizeof(void *));
- memset(col->list, 0, sizeof(void *));
- col->capacity = 1;
+ col->list = malloc(sizeof(void *) * CAPACITY_STEP);
+ memset(col->list, 0, sizeof(void *) * CAPACITY_STEP);
+ col->capacity = CAPACITY_STEP;
}
void collection_free(struct collection *col)
@@ -94,10 +96,10 @@ void collection_add(struct collection *col, void *element)
return;
}
}
- col->list = realloc(col->list, sizeof(void*) * col->capacity * 2);
- memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity);
+ col->list = realloc(col->list, sizeof(void*) * (col->capacity + CAPACITY_STEP));
+ memset(&col->list[col->capacity], 0, sizeof(void *) * CAPACITY_STEP);
col->list[col->capacity] = element;
- col->capacity *= 2;
+ col->capacity += CAPACITY_STEP;
}
void collection_remove(struct collection *col, void *element)