Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-31 01:32:57 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-31 01:32:57 +0400
commitb8547074e18e7645bdfc3e032508f80877592034 (patch)
tree9859220869b0a8cfd63660b26e1a4a37bb87d226 /source/blender/blenlib/intern/BLI_mempool.c
parent427317d8d84345637738d4e4ed60cfd55f1bb595 (diff)
mempool internal change, use unsigned ints where possible (less overhead),
also quiet compiler warning for BLI_LINKSTACK_FREE macro.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 75bbd99b91f..5e1056ca10f 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -64,6 +64,8 @@
/* currently totalloc isnt used */
// #define USE_TOTALLOC
+
+/* when undefined, merge the allocs for BLI_mempool_chunk and its data */
// #define USE_DATA_PTR
typedef struct BLI_freenode {
@@ -80,17 +82,17 @@ typedef struct BLI_mempool_chunk {
struct BLI_mempool {
struct ListBase chunks;
- int esize; /* element size in bytes */
- int csize; /* chunk size in bytes */
- int pchunk; /* number of elements per chunk */
- int flag;
+ unsigned int esize; /* element size in bytes */
+ unsigned int csize; /* chunk size in bytes */
+ unsigned int pchunk; /* number of elements per chunk */
+ unsigned int flag;
/* keeps aligned to 16 bits */
- BLI_freenode *free; /* free element list. Interleaved into chunk datas. */
- int maxchunks; /* use to know how many chunks to keep for BLI_mempool_clear */
- int totused; /* number of elements currently in use */
+ BLI_freenode *free; /* free element list. Interleaved into chunk datas. */
+ unsigned int maxchunks; /* use to know how many chunks to keep for BLI_mempool_clear */
+ unsigned int totused; /* number of elements currently in use */
#ifdef USE_TOTALLOC
- int totalloc; /* number of elements allocated in total */
+ unsigned int totalloc; /* number of elements allocated in total */
#endif
};
@@ -105,7 +107,7 @@ struct BLI_mempool {
/**
* \return the number of chunks to allocate based on how many elements are needed.
*/
-BLI_INLINE int mempool_maxchunks(const int totelem, const int pchunk)
+BLI_INLINE unsigned int mempool_maxchunks(const unsigned int totelem, const unsigned int pchunk)
{
return totelem / pchunk + 1;
}
@@ -147,9 +149,9 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
BLI_freenode *lasttail)
{
BLI_freenode *curnode = NULL;
- const int pchunk_last = pool->pchunk - 1;
+ const unsigned int pchunk_last = pool->pchunk - 1;
char *addr;
- int j;
+ unsigned int j;
mpchunk->next = mpchunk->prev = NULL;
BLI_addtail(&(pool->chunks), mpchunk);
@@ -192,7 +194,7 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
return curnode;
}
-static void mempool_chunk_free(BLI_mempool_chunk *mpchunk, const int flag)
+static void mempool_chunk_free(BLI_mempool_chunk *mpchunk, const unsigned int flag)
{
if (flag & BLI_MEMPOOL_SYSMALLOC) {
#ifdef USE_DATA_PTR
@@ -208,7 +210,7 @@ static void mempool_chunk_free(BLI_mempool_chunk *mpchunk, const int flag)
}
}
-static void mempool_chunk_free_all(ListBase *chunks, const int flag)
+static void mempool_chunk_free_all(ListBase *chunks, const unsigned int flag)
{
BLI_mempool_chunk *mpchunk, *mpchunk_next;
@@ -219,11 +221,12 @@ static void mempool_chunk_free_all(ListBase *chunks, const int flag)
chunks->first = chunks->last = NULL;
}
-BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
+BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem,
+ unsigned int pchunk, unsigned int flag)
{
BLI_mempool *pool = NULL;
BLI_freenode *lasttail = NULL;
- int i, maxchunks;
+ unsigned int i, maxchunks;
/* allocate the pool structure */
if (flag & BLI_MEMPOOL_SYSMALLOC) {
@@ -339,7 +342,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
if (pool->totused == 0) {
BLI_freenode *curnode = NULL;
char *tmpaddr = NULL;
- int i;
+ unsigned int i;
BLI_mempool_chunk *first;
first = BLI_pophead(&pool->chunks);
@@ -361,14 +364,14 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
int BLI_mempool_count(BLI_mempool *pool)
{
- return pool->totused;
+ return (int)pool->totused;
}
-void *BLI_mempool_findelem(BLI_mempool *pool, int index)
+void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index)
{
BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
- if ((index >= 0) && (index < pool->totused)) {
+ if (index < pool->totused) {
/* we could have some faster mem chunk stepping code inline */
BLI_mempool_iter iter;
void *elem;
@@ -455,7 +458,7 @@ static void *bli_mempool_iternext(BLI_mempool_iter *iter)
if (!iter->curchunk || !iter->pool->totused) return NULL;
- ret = ((char *)iter->curchunk->data) + iter->pool->esize * iter->curindex;
+ ret = ((char *)CHUNK_DATA(iter->curchunk)) + (iter->pool->esize * iter->curindex);
iter->curindex++;
@@ -513,7 +516,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
{
BLI_mempool_chunk *mpchunk;
BLI_mempool_chunk *mpchunk_next;
- int maxchunks;
+ unsigned int maxchunks;
ListBase chunks_temp;
BLI_freenode *lasttail = NULL;
@@ -522,12 +525,12 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
maxchunks = pool->maxchunks;
}
else {
- maxchunks = mempool_maxchunks(totelem_reserve, pool->pchunk);
+ maxchunks = mempool_maxchunks((unsigned int)totelem_reserve, pool->pchunk);
}
/* free all after pool->maxchunks */
- for (mpchunk = BLI_findlink(&pool->chunks, maxchunks); mpchunk; mpchunk = mpchunk_next) {
+ for (mpchunk = BLI_findlink(&pool->chunks, (int)maxchunks); mpchunk; mpchunk = mpchunk_next) {
mpchunk_next = mpchunk->next;
BLI_remlink(&pool->chunks, mpchunk);
mempool_chunk_free(mpchunk, pool->flag);