Optimization for mempool initial chunk allocation

Almost all pools allocated 2 chunks on initialization,
every element needed to be added to the free-list which
would never be used for small pools.

Now allocate only one, gives minor speedup for some bmesh operations.
This commit is contained in:
Campbell Barton 2014-04-04 21:20:17 +11:00
parent 896725e0bb
commit 7cb90a611f
1 changed files with 5 additions and 1 deletions

View File

@ -121,10 +121,14 @@ struct BLI_mempool {
/**
* \return the number of chunks to allocate based on how many elements are needed.
*
* \note for small pools 1 is a good default, the elements need to be initialized,
* adding overhead on creation which is redundant if they aren't used.
*
*/
BLI_INLINE unsigned int mempool_maxchunks(const unsigned int totelem, const unsigned int pchunk)
{
return totelem / pchunk + 1;
return (totelem <= pchunk) ? 1 : ((totelem / pchunk) + 1);
}
static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool)