diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-01 17:04:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-01 17:07:18 +0300 |
commit | 2c5dc66d5effd4072f438afb93d70546891ea98e (patch) | |
tree | 8a17360818ab85f238a9a737bbde1dc356dd97c2 /source/blender/blenlib/intern/BLI_mempool.c | |
parent | b1704d18a1cc15f0dbb5fe6e27d80f0fae4b9e72 (diff) |
Optimize mempool iteration
Around ~10% improvement in own tests.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 38d15750761..b7a51f2c48e 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); |