[Bf-blender-cvs] [72e9052] master: BoxPack: remove quad_flags array, replace with inline bit-shift

Campbell Barton noreply at git.blender.org
Thu Apr 24 19:24:06 CEST 2014


Commit: 72e905271316dfe7674648830da518f156fe4386
Author: Campbell Barton
Date:   Fri Apr 25 01:19:06 2014 +1000
https://developer.blender.org/rB72e905271316dfe7674648830da518f156fe4386

BoxPack: remove quad_flags array, replace with inline bit-shift

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

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

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

diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c
index 52d746c..aa90b5e 100644
--- a/source/blender/blenlib/intern/boxpack2d.c
+++ b/source/blender/blenlib/intern/boxpack2d.c
@@ -45,7 +45,8 @@ typedef struct BoxVert {
 	float x;
 	float y;
 
-	int free;  /* could be a char */
+	int free : 8;  /* vert status */
+	int pad  : 24;
 	unsigned int index;
 
 	struct BoxPack *trb; /* top right box */
@@ -67,6 +68,12 @@ typedef struct BoxVert {
 #define BRF 8
 #define CORNERFLAGS (BLF | TRF | TLF | BRF)
 
+BLI_INLINE int quad_flag(unsigned int q)
+{
+	BLI_assert(q < 4 && q >= 0);
+	return (1 << q);
+}
+
 #define BL 0
 #define TR 1
 #define TL 2
@@ -165,7 +172,6 @@ static int vertex_sort(const void *p1, const void *p2)
  *  */
 void BLI_box_pack_2d(BoxPack *boxarray, const unsigned int len, float *tot_width, float *tot_height)
 {
-	const int quad_flags[4] = {BLF, TRF, TLF, BRF};  /* use for looping */
 	unsigned int box_index, verts_pack_len, i, j, k;
 	unsigned int *vertex_pack_indices;  /* an array of indices used for sorting verts */
 	bool isect;
@@ -269,7 +275,7 @@ void BLI_box_pack_2d(BoxPack *boxarray, const unsigned int len, float *tot_width
 			 * */
 
 			for (j = 0; (j < 4) && isect; j++) {
-				if (vert->free & quad_flags[j]) {
+				if (vert->free & quad_flag(j)) {
 					switch (j) {
 						case BL:
 							SET_BOXRIGHT(box, vert->x);
@@ -329,7 +335,7 @@ void BLI_box_pack_2d(BoxPack *boxarray, const unsigned int len, float *tot_width
 						(*tot_height) = max_ff(BOXTOP(box), (*tot_height));
 
 						/* Place the box */
-						vert->free &= ~quad_flags[j];
+						vert->free &= (signed char)(~quad_flag(j));
 
 						switch (j) {
 							case TR:




More information about the Bf-blender-cvs mailing list