diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-08 07:41:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-08 07:41:57 +0400 |
commit | c82371fc06ffb8d2970c985b44167e9a5e0222f1 (patch) | |
tree | 83b20d0562b132b0371b313ac689ed7ba5aa403c /source/blender/blenlib/intern/BLI_mempool.c | |
parent | 4614c63d5dcbf10a16e74235c452fe69ad0cddee (diff) |
Mempool: simplify memory chunk list building
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 3c158faaa1b..21af8afa832 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -186,12 +186,9 @@ static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool) * * \param pool The pool to add the chunk into. * \param mpchunk The new uninitialized chunk (can be malloc'd) - * \param lasttail The last element of the previous chunk * (used when building free chunks initially) - * \return The last chunk, */ -static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpchunk, - BLI_freenode *lasttail) +static void mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpchunk) { const unsigned int esize = pool->esize; BLI_freenode *curnode = CHUNK_DATA(mpchunk); @@ -209,10 +206,6 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc mpchunk->next = NULL; pool->chunk_tail = mpchunk; - if (UNLIKELY(pool->free == NULL)) { - pool->free = curnode; - } - /* loop through the allocated data, building the pointer structures */ j = pool->pchunk; if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) { @@ -229,21 +222,15 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc } } - /* terminate the list (rewind one) - * will be overwritten if 'curnode' gets passed in again as 'lasttail' */ + /* terminate the list (rewind one) */ curnode = NODE_STEP_PREV(curnode); - curnode->next = NULL; + /* 'pool->free' may be NULL, in this case its terminating the list */ + curnode->next = pool->free; + pool->free = CHUNK_DATA(mpchunk); #ifdef USE_TOTALLOC pool->totalloc += pool->pchunk; #endif - - /* final pointer in the previously allocated chunk is wrong */ - if (lasttail) { - lasttail->next = CHUNK_DATA(mpchunk); - } - - return curnode; } static void mempool_chunk_free(BLI_mempool_chunk *mpchunk) @@ -269,7 +256,6 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, unsigned int pchunk, unsigned int flag) { BLI_mempool *pool; - BLI_freenode *lasttail = NULL; unsigned int i, maxchunks; /* allocate the pool structure */ @@ -315,7 +301,7 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, /* allocate the actual chunks */ for (i = 0; i < maxchunks; i++) { BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool); - lasttail = mempool_chunk_add(pool, mpchunk, lasttail); + mempool_chunk_add(pool, mpchunk); } } @@ -333,7 +319,7 @@ void *BLI_mempool_alloc(BLI_mempool *pool) if (UNLIKELY(pool->free == NULL)) { /* need to allocate a new chunk */ BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool); - mempool_chunk_add(pool, mpchunk, NULL); + mempool_chunk_add(pool, mpchunk); } free_pop = pool->free; @@ -613,7 +599,6 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve) unsigned int maxchunks; BLI_mempool_chunk *chunks_temp; - BLI_freenode *lasttail = NULL; #ifdef WITH_MEM_VALGRIND VALGRIND_DESTROY_MEMPOOL(pool); @@ -654,7 +639,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve) while ((mpchunk = chunks_temp)) { chunks_temp = mpchunk->next; - lasttail = mempool_chunk_add(pool, mpchunk, lasttail); + mempool_chunk_add(pool, mpchunk); } } |