[Bf-blender-cvs] [15af15e] master: BLI_buffer: simplify buffer resize

Campbell Barton noreply at git.blender.org
Sun Oct 5 10:33:11 CEST 2014


Commit: 15af15eb56b79188099a00a01c38e545b6533436
Author: Campbell Barton
Date:   Sun Oct 5 10:31:47 2014 +0200
Branches: master
https://developer.blender.org/rB15af15eb56b79188099a00a01c38e545b6533436

BLI_buffer: simplify buffer resize

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

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

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

diff --git a/source/blender/blenlib/intern/buffer.c b/source/blender/blenlib/intern/buffer.c
index 4e57082..9e96205 100644
--- a/source/blender/blenlib/intern/buffer.c
+++ b/source/blender/blenlib/intern/buffer.c
@@ -38,17 +38,14 @@ static void *buffer_alloc(BLI_Buffer *buffer, int len)
 
 static void *buffer_realloc(BLI_Buffer *buffer, int len)
 {
-	if (buffer->flag & BLI_BUFFER_USE_CALLOC) {
-		return MEM_recallocN(buffer->data, buffer->elem_size * len);
-	}
-	else {
-		return MEM_reallocN(buffer->data, buffer->elem_size * len);
-	}
+	return ((buffer->flag & BLI_BUFFER_USE_CALLOC) ?
+	        MEM_recallocN_id : MEM_reallocN_id)
+	        (buffer->data, buffer->elem_size * len, "BLI_Buffer.data");
 }
 
 void BLI_buffer_resize(BLI_Buffer *buffer, int new_count)
 {
-	if (new_count > buffer->alloc_count) {
+	if (UNLIKELY(new_count > buffer->alloc_count)) {
 		if (buffer->flag & BLI_BUFFER_USE_STATIC) {
 			void *orig = buffer->data;
 
@@ -65,12 +62,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, int new_count)
 				buffer->alloc_count = new_count;
 			}
 
-			if (buffer->data) {
-				buffer->data = buffer_realloc(buffer, buffer->alloc_count);
-			}
-			else {
-				buffer->data = buffer_alloc(buffer, buffer->alloc_count);
-			}
+			buffer->data = buffer_realloc(buffer, buffer->alloc_count);
 		}
 	}




More information about the Bf-blender-cvs mailing list