diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-19 07:51:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-19 07:51:17 +0400 |
commit | 9a4da5a2f1adea4928d94b61c0f99b2e8a3c7c9f (patch) | |
tree | 6c3db0f3f1eb6ad8d56ca89cccf8974e3d76dc44 /source/blender | |
parent | bf355362b11b3aaad50f2de881d67bad0209f51e (diff) |
utility function to get a mempool as a pointer array.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_mempool.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index 8fd2166e6f8..20ea89f3abf 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -86,6 +86,11 @@ __attribute__((warn_unused_result)) __attribute__((nonnull(1))) #endif ; +void BLI_mempool_as_array(BLI_mempool *pool, void **data) +#ifdef __GNUC__ +__attribute__((nonnull(1))) +#endif +; /** iteration stuff. note: this may easy to produce bugs with **/ /* private structure */ diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 501c12e9207..0d6b8a44a1e 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -302,13 +302,29 @@ void *BLI_mempool_findelem(BLI_mempool *pool, int index) BLI_mempool_iternew(pool, &iter); for (elem = BLI_mempool_iterstep(&iter); index-- != 0; elem = BLI_mempool_iterstep(&iter)) { /* do nothing */ - }; + } return elem; } return NULL; } +/** + * \param data array of pointers at least the size of 'pool->totused' + */ +void BLI_mempool_as_array(BLI_mempool *pool, void **data) +{ + BLI_mempool_iter iter; + void *elem; + void **p = data; + BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER); + BLI_mempool_iternew(pool, &iter); + for (elem = BLI_mempool_iterstep(&iter); elem; elem = BLI_mempool_iterstep(&iter)) { + *p++ = elem; + } + BLI_assert((p - data) == pool->totused); +} + void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) { BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER); |