Commit 14bedad9 by Russell Belfer

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.
parent d85296ab
...@@ -10,6 +10,11 @@ struct git_pool_page { ...@@ -10,6 +10,11 @@ struct git_pool_page {
char data[GIT_FLEX_ARRAY]; 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_USABLE 4
#define GIT_POOL_MIN_PAGESZ 2 * sizeof(void*) #define GIT_POOL_MIN_PAGESZ 2 * sizeof(void*)
...@@ -150,7 +155,7 @@ void *git_pool_malloc(git_pool *pool, uint32_t items) ...@@ -150,7 +155,7 @@ void *git_pool_malloc(git_pool *pool, uint32_t items)
pool->has_multi_item_alloc = 1; pool->has_multi_item_alloc = 1;
else if (pool->free_list != NULL) { else if (pool->free_list != NULL) {
ptr = pool->free_list; ptr = pool->free_list;
pool->free_list = *((void **)pool->free_list); pool->free_list = ((git_pool_freelist_item *)pool->free_list)->next;
return ptr; return ptr;
} }
...@@ -235,16 +240,19 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b) ...@@ -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) void git_pool_free(git_pool *pool, void *ptr)
{ {
git_pool_freelist_item *item = ptr;
assert(pool && pool->item_size >= sizeof(void*)); assert(pool && pool->item_size >= sizeof(void*));
if (ptr) { if (item) {
*((void **)ptr) = pool->free_list; item->next = pool->free_list;
pool->free_list = ptr; pool->free_list = item;
} }
} }
void git_pool_free_array(git_pool *pool, size_t count, void **ptrs) 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; size_t i;
assert(pool && ptrs && pool->item_size >= sizeof(void*)); 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) ...@@ -253,10 +261,10 @@ void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
return; return;
for (i = count - 1; i > 0; --i) 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; items[i]->next = pool->free_list;
pool->free_list = ptrs[count - 1]; pool->free_list = items[count - 1];
} }
uint32_t git_pool__open_pages(git_pool *pool) uint32_t git_pool__open_pages(git_pool *pool)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment