[Bf-blender-cvs] [b6e083358ee] tmp-workbench-rewrite: BLI_memblock: Allow to use BLI_memblock_elem_get using only elem index

Clément Foucault noreply at git.blender.org
Tue Mar 3 17:35:41 CET 2020


Commit: b6e083358ee475821f3e4e70520b9a29594ecfce
Author: Clément Foucault
Date:   Fri Feb 28 17:29:48 2020 +0100
Branches: tmp-workbench-rewrite
https://developer.blender.org/rBb6e083358ee475821f3e4e70520b9a29594ecfce

BLI_memblock: Allow to use BLI_memblock_elem_get using only elem index

===================================================================

M	source/blender/blenlib/intern/BLI_memblock.c

===================================================================

diff --git a/source/blender/blenlib/intern/BLI_memblock.c b/source/blender/blenlib/intern/BLI_memblock.c
index f7239f1b9d1..45f51893b33 100644
--- a/source/blender/blenlib/intern/BLI_memblock.c
+++ b/source/blender/blenlib/intern/BLI_memblock.c
@@ -182,10 +182,14 @@ void *BLI_memblock_iterstep(BLI_memblock_iter *iter)
   return ptr;
 }
 
-/* Direct access. elem is element index inside the chosen chunk. */
+/* Direct access. elem is element index inside the chosen chunk.
+ * Double usage: You can set chunk to 0 and set the absolute elem index.
+ * The correct chunk will be retrieve. */
 void *BLI_memblock_elem_get(BLI_memblock *mblk, int chunk, int elem)
 {
   BLI_assert(chunk < mblk->chunk_len);
-  BLI_assert(elem < (mblk->chunk_size / mblk->elem_size));
+  int elem_per_chunk = mblk->chunk_size / mblk->elem_size;
+  chunk += elem / elem_per_chunk;
+  elem = elem % elem_per_chunk;
   return (char *)(mblk->chunk_list[chunk]) + mblk->elem_size * elem;
 }



More information about the Bf-blender-cvs mailing list