[Bf-blender-cvs] [2c365c3] compositor-2016: Optimize mempool iteration

Campbell Barton noreply at git.blender.org
Wed Jun 8 21:52:14 CEST 2016


Commit: 2c365c3e7c8a6847d3c536b6ea89f0f8edbdef1a
Author: Campbell Barton
Date:   Thu Jun 2 00:04:51 2016 +1000
Branches: compositor-2016
https://developer.blender.org/rB2c365c3e7c8a6847d3c536b6ea89f0f8edbdef1a

Optimize mempool iteration

Around ~10% improvement in own tests.

===================================================================

M	source/blender/blenlib/intern/BLI_mempool.c

===================================================================

diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 38d1575..b7a51f2 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -605,19 +605,26 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
  */
 void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
 {
-	BLI_freenode *ret;
+	if (UNLIKELY(iter->curchunk == NULL)) {
+		return NULL;
+	}
 
+	const unsigned int esize = iter->pool->esize;
+	BLI_freenode *curnode = POINTER_OFFSET(CHUNK_DATA(iter->curchunk), (esize * iter->curindex));
+	BLI_freenode *ret;
 	do {
-		if (LIKELY(iter->curchunk)) {
-			ret = (BLI_freenode *)(((char *)CHUNK_DATA(iter->curchunk)) + (iter->pool->esize * iter->curindex));
+		ret = curnode;
+
+		if (++iter->curindex != iter->pool->pchunk) {
+			curnode = POINTER_OFFSET(curnode, esize);
 		}
 		else {
-			return NULL;
-		}
-
-		if (UNLIKELY(++iter->curindex == iter->pool->pchunk)) {
 			iter->curindex = 0;
 			iter->curchunk = iter->curchunk->next;
+			if (iter->curchunk == NULL) {
+				return NULL;
+			}
+			curnode = CHUNK_DATA(iter->curchunk);
 		}
 	} while (ret->freeword == FREEWORD);




More information about the Bf-blender-cvs mailing list