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>2011-11-28 01:11:17 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-11-28 01:11:17 +0400
commit1ca7c2e4f3b8dd224782f5c05333fd327d7bc3b3 (patch)
tree2ce8210bc49150fbac29ef27940ecc645e917d42 /source/blender/blenlib/intern/BLI_mempool.c
parent8a37378adbb4383de98171608f5dd1e55234359a (diff)
BLI_mempool_findelem() only worked when no elements were freed, use the iterator for now.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index f8da524d097..0060878587b 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -241,18 +241,19 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
}
}
-void *BLI_mempool_findelem(BLI_mempool *pool, const int index)
+void *BLI_mempool_findelem(BLI_mempool *pool, int index)
{
- if ((index >= 0) && (index < pool->totused)) {
- BLI_mempool_chunk *mpchunk;
- int i= 0;
-
- for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
- if (index < i + pool->pchunk) {
- return ((char *)mpchunk->data) + (pool->esize * (index - i));
- }
- i += pool->pchunk;
- }
+ if (!pool->allow_iter) {
+ fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__);
+ return NULL;
+ }
+ else if ((index >= 0) && (index < pool->totused)) {
+ /* we could have some faster mem chunk stepping code inline */
+ BLI_mempool_iter iter;
+ void *elem;
+ BLI_mempool_iternew(pool, &iter);
+ for (elem= BLI_mempool_iterstep(&iter); index-- != 0; elem= BLI_mempool_iterstep(&iter)) { };
+ return elem;
}
return NULL;