[Bf-blender-cvs] [201b02f2a74] master: Cleanup: simplify lasso reallocation

Campbell Barton noreply at git.blender.org
Mon Oct 16 05:26:22 CEST 2017


Commit: 201b02f2a740290796eedfc8346fabe13e945ad2
Author: Campbell Barton
Date:   Mon Oct 16 13:18:50 2017 +1100
Branches: master
https://developer.blender.org/rB201b02f2a740290796eedfc8346fabe13e945ad2

Cleanup: simplify lasso reallocation

Remove unneeded define, double allocations when increasing.

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

M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_gesture.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/wm.h

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

diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 1c8d12973c6..d8ec26f55da 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -412,7 +412,7 @@ typedef struct wmGesture {
 	int type;		/* gesture type define */
 	int swinid;		/* initial subwindow id where it started */
 	int points;		/* optional, amount of points stored */
-	int size;		/* optional, maximum amount of points stored */
+	int points_alloc;	/* optional, maximum amount of points stored */
 
 	/* For modal operators which may be running idle, waiting for an event to activate the gesture.
 	 * Typically this is set when the user is click-dragging the gesture (border and circle select for eg). */
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index 311b501a179..f66efa72908 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -97,11 +97,11 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type)
 	}
 	else if (ELEM(type, WM_GESTURE_LINES, WM_GESTURE_LASSO)) {
 		short *lasso;
-		gesture->customdata = lasso = MEM_callocN(2 * sizeof(short) * WM_LASSO_MIN_POINTS, "lasso points");
+		gesture->points_alloc = 1024;
+		gesture->customdata = lasso = MEM_mallocN(sizeof(short[2]) * gesture->points_alloc, "lasso points");
 		lasso[0] = event->x - sx;
 		lasso[1] = event->y - sy;
 		gesture->points = 1;
-		gesture->size = WM_LASSO_MIN_POINTS;
 	}
 	
 	return gesture;
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 330a18eeda5..6fdc0a0a8c0 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2692,28 +2692,24 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	switch (event->type) {
 		case MOUSEMOVE:
 		case INBETWEEN_MOUSEMOVE:
-			
+
 			wm_gesture_tag_redraw(C);
-			
+
 			wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
 
-			if (gesture->points == gesture->size) {
-				short *old_lasso = gesture->customdata;
-				gesture->customdata = MEM_callocN(2 * sizeof(short) * (gesture->size + WM_LASSO_MIN_POINTS), "lasso points");
-				memcpy(gesture->customdata, old_lasso, 2 * sizeof(short) * gesture->size);
-				gesture->size = gesture->size + WM_LASSO_MIN_POINTS;
-				MEM_freeN(old_lasso);
-				// printf("realloc\n");
+			if (gesture->points == gesture->points_alloc) {
+				gesture->points_alloc *= 2;
+				gesture->customdata = MEM_reallocN(gesture->customdata, sizeof(short[2]) * gesture->points_alloc);
 			}
 
 			{
 				int x, y;
 				short *lasso = gesture->customdata;
-				
+
 				lasso += (2 * gesture->points - 2);
 				x = (event->x - sx - lasso[0]);
 				y = (event->y - sy - lasso[1]);
-				
+
 				/* make a simple distance check to get a smoother lasso
 				 * add only when at least 2 pixels between this and previous location */
 				if ((x * x + y * y) > 4) {
@@ -2724,7 +2720,7 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
 				}
 			}
 			break;
-			
+
 		case LEFTMOUSE:
 		case MIDDLEMOUSE:
 		case RIGHTMOUSE:
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 1206c2b194a..cb88ca3a474 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -60,7 +60,6 @@ void wm_window_keymap(wmKeyConfig *keyconf);
 void wm_tweakevent_test(bContext *C, const wmEvent *event, int action);
 
 /* wm_gesture.c */
-#define WM_LASSO_MIN_POINTS		1024
 void wm_gesture_draw(struct wmWindow *win);
 int wm_gesture_evaluate(wmGesture *gesture);
 void wm_gesture_tag_redraw(bContext *C);



More information about the Bf-blender-cvs mailing list