[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42473] branches/bmesh/blender/source/ blender/blenlib/BLI_array.h: optimization for BLI_array_growitems ( better put - improve inefficient method), BLI_array_growone was being called in a loop, even if the size of the allocated array was big enough for all items.

Campbell Barton ideasman42 at gmail.com
Wed Dec 7 01:18:08 CET 2011


Revision: 42473
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42473
Author:   campbellbarton
Date:     2011-12-07 00:18:08 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
optimization for BLI_array_growitems (better put - improve inefficient method), BLI_array_growone was being called in a loop, even if the size of the allocated array was big enough for all items.

In this case now just adjust the count value since theres no need to loop,
when the allocation is not big enough BLI_array_growone in a loop is still used though.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenlib/BLI_array.h

Modified: branches/bmesh/blender/source/blender/blenlib/BLI_array.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_array.h	2011-12-07 00:11:39 UTC (rev 42472)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_array.h	2011-12-07 00:18:08 UTC (rev 42473)
@@ -89,26 +89,27 @@
 #define BLI_array_count(arr) _##arr##_count
 
 /* grow the array by one.  zeroes the new elements. */
-#define _BLI_array_growone(arr)  (                                            \
+#define _bli_array_growone(arr)  (                                            \
 	(BLI_array_totalsize(arr) > _##arr##_count) ?                             \
-		++_##arr##_count :  (                                                 \
-		(void) (_##arr##_tmp = MEM_callocN(                                   \
-		        sizeof(*arr)*(_##arr##_count*2+2),                            \
-		        #arr " " __FILE__ ":" STRINGIFY(__LINE__)                     \
-		        )                                                             \
-		        ),                                                            \
-		(void) (arr && memcpy(_##arr##_tmp,                                   \
-		                      arr,                                            \
-		                      sizeof(*arr) * _##arr##_count)                  \
-		        ),                                                            \
-		(void) (arr && ((void *)(arr) != (void*)_##arr##_static ?             \
-		        (MEM_freeN(arr), arr) :                                       \
-		        arr)                                                          \
-		        ),                                                            \
-		(void)(arr = _##arr##_tmp                                             \
-		       ),                                                             \
-		_##arr##_count++                                                      \
-	)                                                                         \
+	    ++_##arr##_count :                                                    \
+	    (                                                                     \
+	        (void) (_##arr##_tmp = MEM_callocN(                               \
+	                sizeof(*arr)*(_##arr##_count*2+2),                        \
+	                #arr " " __FILE__ ":" STRINGIFY(__LINE__)                 \
+	                )                                                         \
+	                ),                                                        \
+	        (void) (arr && memcpy(_##arr##_tmp,                               \
+	                              arr,                                        \
+	                              sizeof(*arr) * _##arr##_count)              \
+	                ),                                                        \
+	        (void) (arr && ((void *)(arr) != (void*)_##arr##_static ?         \
+	                (MEM_freeN(arr), arr) :                                   \
+	                arr)                                                      \
+	                ),                                                        \
+	        (void) (arr = _##arr##_tmp                                        \
+	                ),                                                        \
+	        _##arr##_count++                                                  \
+	    )                                                                     \
 )
 
 
@@ -116,7 +117,7 @@
 #define BLI_array_growone(arr)  (                                             \
 	((void *)(arr)==NULL && (void *)(_##arr##_static) != NULL) ?              \
 		((arr=(void*)_##arr##_static), ++_##arr##_count) :                    \
-		_BLI_array_growone(arr)                                               \
+		_bli_array_growone(arr)                                               \
 )
 
 
@@ -137,7 +138,10 @@
 /* grow an array by a specified number of items. */
 /* TODO, this could be done in a less crappy way by not looping - campbell */
 #define BLI_array_growitems(arr, num)                                         \
-	{                                                                         \
+	if ((BLI_array_totalsize(arr) - _##arr##_count) >= num) {                 \
+	    _##arr##_count += num;                                                \
+	}                                                                         \
+	else {                                                                    \
 		int _i;                                                               \
 		for (_i = 0; _i < (num); _i++) {                                      \
 			BLI_array_growone(arr);                                           \




More information about the Bf-blender-cvs mailing list