diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-31 01:32:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-31 01:32:57 +0400 |
commit | b8547074e18e7645bdfc3e032508f80877592034 (patch) | |
tree | 9859220869b0a8cfd63660b26e1a4a37bb87d226 /source | |
parent | 427317d8d84345637738d4e4ed60cfd55f1bb595 (diff) |
mempool internal change, use unsigned ints where possible (less overhead),
also quiet compiler warning for BLI_LINKSTACK_FREE macro.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_linklist_stack.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_mempool.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 49 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 4 |
5 files changed, 36 insertions, 32 deletions
diff --git a/source/blender/blenlib/BLI_linklist_stack.h b/source/blender/blenlib/BLI_linklist_stack.h index 82ca986d9ca..e9cf820c6c8 100644 --- a/source/blender/blenlib/BLI_linklist_stack.h +++ b/source/blender/blenlib/BLI_linklist_stack.h @@ -81,7 +81,7 @@ BLI_mempool_destroy(_##var##_pool); \ _##var##_pool = NULL; (void)_##var##_pool; \ var = NULL; (void)var; \ - (void)_##var##_type; \ + (void)&(_##var##_type); \ } (void)0 #include "BLI_linklist.h" diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index 147acdc6d97..153a3735182 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -48,7 +48,8 @@ typedef struct BLI_mempool BLI_mempool; * first four bytes of the elements never contain the character string * 'free'. use with care.*/ -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) #ifdef __GNUC__ __attribute__((malloc)) __attribute__((warn_unused_result)) @@ -94,7 +95,7 @@ int BLI_mempool_count(BLI_mempool *pool) __attribute__((nonnull(1))) #endif ; -void *BLI_mempool_findelem(BLI_mempool *pool, int index) +void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) #ifdef __GNUC__ __attribute__((warn_unused_result)) __attribute__((nonnull(1))) @@ -133,7 +134,7 @@ __attribute__((nonnull(1, 2))) typedef struct BLI_mempool_iter { BLI_mempool *pool; struct BLI_mempool_chunk *curchunk; - int curindex; + unsigned int curindex; } BLI_mempool_iter; /* flag */ diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 9c8231a473b..58c4133fd61 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -181,7 +181,7 @@ BLI_INLINE Entry *ghash_lookup_entry(GHash *gh, const void *key) static GHash *ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info, const unsigned int nentries_reserve, - const size_t entry_size) + const unsigned int entry_size) { GHash *gh = MEM_mallocN(sizeof(*gh), info); @@ -199,7 +199,7 @@ static GHash *ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info, } gh->buckets = MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); - gh->entrypool = BLI_mempool_create((int)entry_size, 64, 64, 0); + gh->entrypool = BLI_mempool_create(entry_size, 64, 64, 0); return gh; } @@ -320,7 +320,7 @@ GHash *BLI_ghash_new_ex(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info, { return ghash_new(hashfp, cmpfp, info, nentries_reserve, - sizeof(Entry)); + (unsigned int)sizeof(Entry)); } /** 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); diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 5e07920b6e3..54ae0d385ef 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -184,7 +184,7 @@ BLI_INLINE EdgeEntry *edgehash_lookup_entry(EdgeHash *eh, unsigned int v0, unsig static EdgeHash *edgehash_new(const char *info, const unsigned int nentries_reserve, - const size_t entry_size) + const unsigned int entry_size) { EdgeHash *eh = MEM_mallocN(sizeof(*eh), info); @@ -199,7 +199,7 @@ static EdgeHash *edgehash_new(const char *info, } eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets"); - eh->epool = BLI_mempool_create((int)entry_size, 512, 512, BLI_MEMPOOL_SYSMALLOC); + eh->epool = BLI_mempool_create(entry_size, 512, 512, BLI_MEMPOOL_SYSMALLOC); return eh; } |