[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44594] trunk/blender/source/blender: Code Cleanup: update to mempool, use flag rather then bool args.

Campbell Barton ideasman42 at gmail.com
Thu Mar 1 23:59:26 CET 2012


Revision: 44594
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44594
Author:   campbellbarton
Date:     2012-03-01 22:59:18 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
Code Cleanup: update to mempool, use flag rather then bool args.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/customdata.c
    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
    trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
    trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
    trunk/blender/source/blender/bmesh/intern/bmesh_walkers.c
    trunk/blender/source/blender/bmesh/operators/bmo_create.c
    trunk/blender/source/blender/editors/mesh/knifetool.c
    trunk/blender/source/blender/imbuf/intern/moviecache.c

Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c	2012-03-01 22:59:18 UTC (rev 44594)
@@ -2132,7 +2132,7 @@
 
 	/* If there are no layers, no pool is needed just yet */
 	if (data->totlayer) {
-		data->pool = BLI_mempool_create(data->totsize, totelem, chunksize, TRUE, FALSE);
+		data->pool = BLI_mempool_create(data->totsize, totelem, chunksize, BLI_MEMPOOL_SYSMALLOC);
 	}
 }
 

Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h	2012-03-01 22:59:18 UTC (rev 44594)
@@ -48,8 +48,7 @@
  * first four bytes of the elements never contain the character string
  * 'free'.  use with care.*/
 
-BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk,
-                                short use_sysmalloc, short allow_iter);
+BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int flag);
 void *BLI_mempool_alloc(BLI_mempool *pool);
 void *BLI_mempool_calloc(BLI_mempool *pool);
 void  BLI_mempool_free(BLI_mempool *pool, void *addr);
@@ -65,6 +64,12 @@
 	int curindex;
 } BLI_mempool_iter;
 
+/* flag */
+enum {
+	BLI_MEMPOOL_SYSMALLOC  = (1 << 0),
+	BLI_MEMPOOL_ALLOW_ITER = (1 << 1)
+};
+
 void  BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter);
 void *BLI_mempool_iterstep(BLI_mempool_iter *iter);
 

Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2012-03-01 22:59:18 UTC (rev 44594)
@@ -61,7 +61,7 @@
 	GHash *gh= MEM_mallocN(sizeof(*gh), info);
 	gh->hashfp= hashfp;
 	gh->cmpfp= cmpfp;
-	gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, FALSE, FALSE);
+	gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, 0);
 
 	gh->cursize= 0;
 	gh->nentries= 0;

Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2012-03-01 22:59:18 UTC (rev 44594)
@@ -71,7 +71,7 @@
 	int esize;         /* element size in bytes */
 	int csize;         /* chunk size in bytes */
 	int pchunk;        /* number of elements per chunk */
-	short use_sysmalloc, allow_iter;
+	int flag;
 	/* keeps aligned to 16 bits */
 
 	BLI_freenode *free;	             /* free element list. Interleaved into chunk datas.*/
@@ -81,8 +81,7 @@
 
 #define MEMPOOL_ELEM_SIZE_MIN (sizeof(void *) * 2)
 
-BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk,
-                                short use_sysmalloc, short allow_iter)
+BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int flag)
 {
 	BLI_mempool  *pool = NULL;
 	BLI_freenode *lasttail = NULL, *curnode = NULL;
@@ -93,29 +92,38 @@
 		esize = MEMPOOL_ELEM_SIZE_MIN;
 
 	/*allocate the pool structure*/
-	pool = use_sysmalloc ? malloc(sizeof(BLI_mempool)) : MEM_mallocN(sizeof(BLI_mempool), "memory pool");
-	pool->esize = allow_iter ? MAX2(esize, sizeof(BLI_freenode)) : esize;
-	pool->use_sysmalloc = use_sysmalloc;
+	pool = (flag & BLI_MEMPOOL_SYSMALLOC) ? malloc(sizeof(BLI_mempool)) : MEM_mallocN(sizeof(BLI_mempool), "memory pool");
+	pool->esize = (flag & BLI_MEMPOOL_ALLOW_ITER) ? MAX2(esize, sizeof(BLI_freenode)) : esize;
+	pool->flag = flag;
 	pool->pchunk = pchunk;
 	pool->csize = esize * pchunk;
 	pool->chunks.first = pool->chunks.last = NULL;
 	pool->totused= 0;
-	pool->allow_iter= allow_iter;
 	
 	maxchunks = tote / pchunk + 1;
 	if (maxchunks==0) maxchunks = 1;
 
-	/*allocate the actual chunks*/
-	for (i=0; i < maxchunks; i++) {
-		BLI_mempool_chunk *mpchunk = use_sysmalloc ? malloc(sizeof(BLI_mempool_chunk)) : MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
+	/* allocate the actual chunks */
+	for (i = 0; i < maxchunks; i++) {
+		BLI_mempool_chunk *mpchunk;
+
+		if (flag & BLI_MEMPOOL_SYSMALLOC) {
+			mpchunk       = malloc(sizeof(BLI_mempool_chunk));
+			mpchunk->data = malloc(pool->csize);
+		}
+		else {
+			mpchunk       = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
+			mpchunk->data = MEM_mallocN(pool->csize, "BLI Mempool Chunk Data");
+		}
+
 		mpchunk->next = mpchunk->prev = NULL;
-		mpchunk->data = use_sysmalloc ? malloc(pool->csize) : MEM_mallocN(pool->csize, "BLI Mempool Chunk Data");
 		BLI_addtail(&(pool->chunks), mpchunk);
 		
 		if (i==0) {
 			pool->free = mpchunk->data; /*start of the list*/
-			if (pool->allow_iter)
+			if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 				pool->free->freeword = FREEWORD;
+			}
 		}
 
 		/*loop through the allocated data, building the pointer structures*/
@@ -123,7 +131,7 @@
 			curnode = ((BLI_freenode*)addr);
 			addr += pool->esize;
 			curnode->next = (BLI_freenode*)addr;
-			if (pool->allow_iter) {
+			if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 				if (j != pool->pchunk-1)
 					curnode->next->freeword = FREEWORD;
 				curnode->freeword = FREEWORD;
@@ -132,8 +140,9 @@
 		/*final pointer in the previously allocated chunk is wrong.*/
 		if (lasttail) {
 			lasttail->next = mpchunk->data;
-			if (pool->allow_iter)
+			if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 				lasttail->freeword = FREEWORD;
+			}
 		}
 
 		/*set the end of this chunks memoryy to the new tail for next iteration*/
@@ -158,20 +167,32 @@
 		int j;
 
 		/*need to allocate a new chunk*/
-		BLI_mempool_chunk *mpchunk = pool->use_sysmalloc ? malloc(sizeof(BLI_mempool_chunk)) :  MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
+		BLI_mempool_chunk *mpchunk;
+
+		if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
+			mpchunk       = malloc(sizeof(BLI_mempool_chunk));
+			mpchunk->data = malloc(pool->csize);
+		}
+		else {
+			mpchunk       = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
+			mpchunk->data = MEM_mallocN(pool->csize, "BLI_Mempool Chunk Data");
+		}
+
 		mpchunk->next = mpchunk->prev = NULL;
-		mpchunk->data = pool->use_sysmalloc ? malloc(pool->csize) : MEM_mallocN(pool->csize, "BLI_Mempool Chunk Data");
 		BLI_addtail(&(pool->chunks), mpchunk);
 
-		pool->free = mpchunk->data; /*start of the list*/
-		if (pool->allow_iter)
+		pool->free = mpchunk->data; /* start of the list */
+
+		if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 			pool->free->freeword = FREEWORD;
+		}
+
 		for(addr = mpchunk->data, j=0; j < pool->pchunk; j++) {
 			curnode = ((BLI_freenode*)addr);
 			addr += pool->esize;
 			curnode->next = (BLI_freenode*)addr;
 
-			if (pool->allow_iter) {
+			if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 				curnode->freeword = FREEWORD;
 				if (j != pool->pchunk-1)
 					curnode->next->freeword = FREEWORD;
@@ -183,8 +204,10 @@
 	}
 
 	retval = pool->free;
-	if (pool->allow_iter)
+
+	if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 		pool->free->freeword = 0x7FFFFFFF;
+	}
 
 	pool->free = pool->free->next;
 	//memset(retval, 0, pool->esize);
@@ -203,8 +226,10 @@
 {
 	BLI_freenode *newhead = addr;
 
-	if (pool->allow_iter)
+	if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
 		newhead->freeword = FREEWORD;
+	}
+
 	newhead->next = pool->free;
 	pool->free = newhead;
 
@@ -221,13 +246,19 @@
 
 		BLI_remlink(&pool->chunks, first);
 
-		for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
-			if (pool->use_sysmalloc) free(mpchunk->data);
-			else                     MEM_freeN(mpchunk->data);
+		if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
+			for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
+				free(mpchunk->data);
+			}
+			BLI_freelist(&(pool->chunks));
 		}
+		else {
+			for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
+				MEM_freeN(mpchunk->data);
+			}
+			BLI_freelistN(&(pool->chunks));
+		}
 
-		pool->use_sysmalloc ? BLI_freelist(&(pool->chunks)) : BLI_freelistN(&(pool->chunks));
-		
 		BLI_addtail(&pool->chunks, first);
 		pool->totalloc = pool->pchunk;
 
@@ -248,7 +279,7 @@
 
 void *BLI_mempool_findelem(BLI_mempool *pool, int index)
 {
-	if (!pool->allow_iter) {
+	if (!(pool->flag & BLI_MEMPOOL_ALLOW_ITER)) {
 		fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__);
 		return NULL;
 	}
@@ -266,7 +297,7 @@
 
 void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
 {
-	if (!pool->allow_iter) {
+	if (!(pool->flag & BLI_MEMPOOL_ALLOW_ITER)) {
 		fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__);
 		iter->curchunk = NULL;
 		iter->curindex = 0;
@@ -346,7 +377,7 @@
 {
 	BLI_mempool_chunk *mpchunk=NULL;
 
-	if (pool->use_sysmalloc) {
+	if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
 		for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
 			free(mpchunk->data);
 		}

Modified: trunk/blender/source/blender/blenlib/intern/edgehash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/edgehash.c	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/blenlib/intern/edgehash.c	2012-03-01 22:59:18 UTC (rev 44594)
@@ -83,7 +83,7 @@
 	eh->nbuckets = _ehash_hashsizes[eh->cursize];
 	
 	eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets 2");
-	eh->epool = BLI_mempool_create(sizeof(EdgeEntry), 512, 512, TRUE, FALSE);
+	eh->epool = BLI_mempool_create(sizeof(EdgeEntry), 512, 512, BLI_MEMPOOL_SYSMALLOC);
 
 	return eh;
 }

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c	2012-03-01 22:17:04 UTC (rev 44593)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c	2012-03-01 22:59:18 UTC (rev 44594)
@@ -48,17 +48,17 @@
 
 static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
 {
-	bm->vpool =        BLI_mempool_create(sizeof(BMVert),     allocsize->totvert, allocsize->totvert, FALSE, TRUE);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list