diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-29 07:39:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-29 07:39:59 +0400 |
commit | d14edecabff7dcae1833fe0288f1da33a7dbbd8c (patch) | |
tree | d1ed59a490c22ef7d40aa1a2aebe994e8e840ec1 /source/blender/blenlib | |
parent | fc74eea7a46bbdae6b928560c6a4378a5826e185 (diff) |
optimized mempool iterator from bmesh
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 0060878587b..5e64ed2e3e6 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -274,6 +274,9 @@ void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) iter->curindex = 0; } +#if 0 +/* unoptimized, more readable */ + static void *bli_mempool_iternext(BLI_mempool_iter *iter) { void *ret = NULL; @@ -303,6 +306,37 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter) return ret; } +#else + +/* optimized version of code above */ + +void *BLI_mempool_iterstep(BLI_mempool_iter *iter) +{ + BLI_freenode *ret; + + if (UNLIKELY(iter->pool->totused == 0)) { + return NULL; + } + + do { + if (LIKELY(iter->curchunk)) { + ret = (BLI_freenode *)(((char*)iter->curchunk->data) + iter->pool->esize*iter->curindex); + } + else { + return NULL; + } + + if (UNLIKELY(++iter->curindex >= iter->pool->pchunk)) { + iter->curindex = 0; + iter->curchunk = iter->curchunk->next; + } + } while (ret->freeword == FREEWORD); + + return ret; +} + +#endif + void BLI_mempool_destroy(BLI_mempool *pool) { BLI_mempool_chunk *mpchunk=NULL; |