Added pool freelist struct for readability This adds a git_pool_freelist_item struct that makes it a little easier to follow what's going on with the pool free list block management code. It is functionally neutral.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/pool.c b/src/pool.c
index 6b78a0b..33ea74f 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -10,6 +10,11 @@ struct git_pool_page {
char data[GIT_FLEX_ARRAY];
};
+typedef struct git_pool_freelist_item git_pool_freelist_item;
+struct git_pool_freelist_item {
+ git_pool_freelist_item *next;
+};
+
#define GIT_POOL_MIN_USABLE 4
#define GIT_POOL_MIN_PAGESZ 2 * sizeof(void*)
@@ -150,7 +155,7 @@ void *git_pool_malloc(git_pool *pool, uint32_t items)
pool->has_multi_item_alloc = 1;
else if (pool->free_list != NULL) {
ptr = pool->free_list;
- pool->free_list = *((void **)pool->free_list);
+ pool->free_list = ((git_pool_freelist_item *)pool->free_list)->next;
return ptr;
}
@@ -235,16 +240,19 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
void git_pool_free(git_pool *pool, void *ptr)
{
+ git_pool_freelist_item *item = ptr;
+
assert(pool && pool->item_size >= sizeof(void*));
- if (ptr) {
- *((void **)ptr) = pool->free_list;
- pool->free_list = ptr;
+ if (item) {
+ item->next = pool->free_list;
+ pool->free_list = item;
}
}
void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
{
+ git_pool_freelist_item **items = (git_pool_freelist_item **)ptrs;
size_t i;
assert(pool && ptrs && pool->item_size >= sizeof(void*));
@@ -253,10 +261,10 @@ void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
return;
for (i = count - 1; i > 0; --i)
- *((void **)ptrs[i]) = ptrs[i - 1];
+ items[i]->next = items[i - 1];
- *((void **)ptrs[0]) = pool->free_list;
- pool->free_list = ptrs[count - 1];
+ items[i]->next = pool->free_list;
+ pool->free_list = items[count - 1];
}
uint32_t git_pool__open_pages(git_pool *pool)