[Bf-blender-cvs] [7980c7c] master: BLI_array_store: store max size in BArrayInfo

Campbell Barton noreply at git.blender.org
Thu Jun 2 10:21:07 CEST 2016


Commit: 7980c7c10f0270843e68bdad3a752aa2154d226a
Author: Campbell Barton
Date:   Thu Jun 2 18:01:03 2016 +1000
Branches: master
https://developer.blender.org/rB7980c7c10f0270843e68bdad3a752aa2154d226a

BLI_array_store: store max size in BArrayInfo

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

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

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

diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c
index b559061..2e11257 100644
--- a/source/blender/blenlib/intern/array_store.c
+++ b/source/blender/blenlib/intern/array_store.c
@@ -229,7 +229,9 @@ typedef struct BArrayInfo {
 
 	/* pre-calculated */
 	size_t chunk_byte_size;
+	/* min/max limits (inclusive) */
 	size_t chunk_byte_size_min;
+	size_t chunk_byte_size_max;
 
 	size_t accum_read_ahead_bytes;
 #ifdef USE_HASH_TABLE_ACCUMULATE
@@ -455,7 +457,7 @@ static void bchunk_list_ensure_min_size_last(
 		if (MIN2(chunk_prev->data_len, chunk_curr->data_len) < info->chunk_byte_size_min) {
 			const size_t data_merge_len = chunk_prev->data_len + chunk_curr->data_len;
 			/* we could pass, but no need */
-			if (data_merge_len <= (info->chunk_byte_size * BCHUNK_SIZE_MAX_MUL)) {
+			if (data_merge_len <= info->chunk_byte_size_max) {
 				/* we have enough space to merge */
 
 				/* remove last from linklist */
@@ -548,6 +550,8 @@ static void bchunk_list_append_data(
         const ubyte *data, const size_t data_len)
 {
 	BLI_assert(data_len != 0);
+	BLI_assert(data_len <= info->chunk_byte_size_max);
+
 	// printf("data_len: %d\n", data_len);
 #ifdef USE_MERGE_CHUNKS
 	if (!BLI_listbase_is_empty(&chunk_list->chunk_refs)) {
@@ -1374,6 +1378,7 @@ BArrayStore *BLI_array_store_create(
 	bs->info.chunk_byte_size = chunk_count * stride;
 #ifdef USE_MERGE_CHUNKS
 	bs->info.chunk_byte_size_min = MAX2(1u, chunk_count / BCHUNK_SIZE_MIN_DIV) * stride;
+	bs->info.chunk_byte_size_max = (chunk_count * BCHUNK_SIZE_MAX_MUL) * stride;
 #endif
 
 #ifdef USE_HASH_TABLE_ACCUMULATE




More information about the Bf-blender-cvs mailing list