Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-04 23:40:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-04 23:40:50 +0400
commit2497084744b9a106cf200f8f3afa20557e6070b8 (patch)
treeb6b2036aab1cc5ccd3da68bb1a4d74dca31ca5b5 /source/blender/blenlib/intern/BLI_mempool.c
parentfdc336510a16496bf0e215604a5afd976e613940 (diff)
mempool api cleanup: differentiate mempool functions that allocate a pointer lookup table from allocating the data as a contiguous array,
call these functions BLI_mempool_as_table(), BLI_mempool_as_array(), the N prefixed versions of these functions return newly allocated arrays.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index f370f32c31d..bb326a23d59 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -334,38 +334,57 @@ void *BLI_mempool_findelem(BLI_mempool *pool, int index)
}
/**
+ * Fill in \a data with pointers to each element of the mempool,
+ * to create lookup table.
+ *
* \param data array of pointers at least the size of 'pool->totused'
*/
-void BLI_mempool_as_array(BLI_mempool *pool, void **data)
+void BLI_mempool_as_table(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)) {
+ while ((elem = BLI_mempool_iterstep(&iter))) {
*p++ = elem;
}
BLI_assert((p - data) == pool->totused);
}
/**
- * Allocate an array from the mempool.
+ * A version of #BLI_mempool_as_table that allocates and returns the data.
*/
-void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
+void **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr)
{
- char *data = MEM_mallocN((size_t)(pool->totused * pool->esize), allocstr);
+ void **data = MEM_mallocN((size_t)pool->totused * sizeof(void *), allocstr);
+ BLI_mempool_as_table(pool, data);
+ return data;
+}
+
+/**
+ * Fill in \a data with the contents of the mempool.
+ */
+void BLI_mempool_as_array(BLI_mempool *pool, void *data)
+{
+ BLI_mempool_iter iter;
+ char *elem, *p = data;
BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
- if (data) {
- BLI_mempool_iter iter;
- char *elem, *p = data;
- BLI_mempool_iternew(pool, &iter);
- for (elem = BLI_mempool_iterstep(&iter); elem; elem = BLI_mempool_iterstep(&iter)) {
- memcpy(p, elem, (size_t)pool->esize);
- p += pool->esize;
- }
- BLI_assert((p - data) == pool->totused * pool->esize);
+ BLI_mempool_iternew(pool, &iter);
+ while ((elem = BLI_mempool_iterstep(&iter))) {
+ memcpy(p, elem, (size_t)pool->esize);
+ p += pool->esize;
}
+ BLI_assert((p - (char *)data) == pool->totused * pool->esize);
+}
+
+/**
+ * A version of #BLI_mempool_as_array that allocates and returns the data.
+ */
+void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
+{
+ char *data = MEM_mallocN((size_t)(pool->totused * pool->esize), allocstr);
+ BLI_mempool_as_array(pool, data);
return data;
}