[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59674] trunk/blender/source/blender/ blenlib: mempool internal change, use unsigned ints where possible ( less overhead),
Campbell Barton
ideasman42 at gmail.com
Fri Aug 30 23:32:57 CEST 2013
Revision: 59674
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59674
Author: campbellbarton
Date: 2013-08-30 21:32:57 +0000 (Fri, 30 Aug 2013)
Log Message:
-----------
mempool internal change, use unsigned ints where possible (less overhead),
also quiet compiler warning for BLI_LINKSTACK_FREE macro.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_linklist_stack.h
trunk/blender/source/blender/blenlib/BLI_mempool.h
trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
trunk/blender/source/blender/blenlib/intern/edgehash.c
Modified: trunk/blender/source/blender/blenlib/BLI_linklist_stack.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_linklist_stack.h 2013-08-30 20:26:57 UTC (rev 59673)
+++ trunk/blender/source/blender/blenlib/BLI_linklist_stack.h 2013-08-30 21:32:57 UTC (rev 59674)
@@ -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"
Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h 2013-08-30 20:26:57 UTC (rev 59673)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h 2013-08-30 21:32:57 UTC (rev 59674)
@@ -48,7 +48,8 @@
* 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 @@
__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 @@
typedef struct BLI_mempool_iter {
BLI_mempool *pool;
struct BLI_mempool_chunk *curchunk;
- int curindex;
+ unsigned int curindex;
} BLI_mempool_iter;
/* flag */
Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-30 20:26:57 UTC (rev 59673)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-30 21:32:57 UTC (rev 59674)
@@ -181,7 +181,7 @@
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 @@
}
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 @@
{
return ghash_new(hashfp, cmpfp, info,
nentries_reserve,
- sizeof(Entry));
+ (unsigned int)sizeof(Entry));
}
/**
Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-08-30 20:26:57 UTC (rev 59673)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-08-30 21:32:57 UTC (rev 59674)
@@ -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 @@
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 @@
/**
* \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 @@
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 @@
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_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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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);
Modified: trunk/blender/source/blender/blenlib/intern/edgehash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-08-30 20:26:57 UTC (rev 59673)
+++ trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-08-30 21:32:57 UTC (rev 59674)
@@ -184,7 +184,7 @@
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 @@
}
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;
}
More information about the Bf-blender-cvs
mailing list