[Bf-blender-cvs] [d419e2e] master: WM: add WM_operator_properties_create_ptr

Campbell Barton noreply at git.blender.org
Fri Jul 11 07:08:56 CEST 2014


Commit: d419e2e90cc3bb3fd6aa89baab8b4f4caa2001e1
Author: Campbell Barton
Date:   Fri Jul 11 15:07:55 2014 +1000
https://developer.blender.org/rBd419e2e90cc3bb3fd6aa89baab8b4f4caa2001e1

WM: add WM_operator_properties_create_ptr

Call operator types directly and avoid a lookup when their known.

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

M	source/blender/blenlib/intern/smallhash.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_ops.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c
index d6b2383..adcd10f 100644
--- a/source/blender/blenlib/intern/smallhash.c
+++ b/source/blender/blenlib/intern/smallhash.c
@@ -44,8 +44,6 @@
  *
  * Note that the values and keys are often pointers or index values,
  * use the maximum values to avoid real pointers colliding with magic numbers.
- *
- * \note these have the SMHASH prefix because we may want to make them public.
  */
 
 #include <string.h>
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index e04fef3..d37660a 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -633,7 +633,7 @@ static void ui_apply_but_funcs_after(bContext *C)
 		}
 
 		if (after.optype)
-			WM_operator_name_call(C, after.optype->idname, after.opcontext, (after.opptr) ? &opptr : NULL);
+			WM_operator_name_call_ptr(C, after.optype, after.opcontext, (after.opptr) ? &opptr : NULL);
 
 		if (after.opptr)
 			WM_operator_properties_free(&opptr);
@@ -8476,7 +8476,7 @@ static int ui_handler_popup(bContext *C, const wmEvent *event, void *userdata)
 			if (temp.popup_func)
 				temp.popup_func(C, temp.popup_arg, temp.retvalue);
 			if (temp.optype)
-				WM_operator_name_call(C, temp.optype->idname, temp.opcontext, NULL);
+				WM_operator_name_call_ptr(C, temp.optype, temp.opcontext, NULL);
 		}
 		else if (temp.cancel_func)
 			temp.cancel_func(C, temp.popup_arg);
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 316a4d3..877a993 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -693,6 +693,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
 	int ret = OPERATOR_CANCELLED;
 
 	if (but) {
+		wmOperatorType *ot;
 		PointerRNA ptr;
 		char popath[FILE_MAX];
 		const char *root = U.i18ndir;
@@ -714,7 +715,8 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
 			                                   "Directory' path to a valid directory");
 			return OPERATOR_CANCELLED;
 		}
-		if (!WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0)) {
+		ot = WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0);
+		if (ot == NULL) {
 			BKE_reportf(op->reports, RPT_ERROR, "Could not find operator '%s'! Please enable ui_translate addon "
 			                                    "in the User Preferences", EDTSRC_I18N_OP_NAME);
 			return OPERATOR_CANCELLED;
@@ -730,7 +732,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
 		uiButGetStrInfo(C, but, &but_label, &rna_label, &enum_label, &but_tip, &rna_tip, &enum_tip,
 		                &rna_struct, &rna_prop, &rna_enum, &rna_ctxt, NULL);
 
-		WM_operator_properties_create(&ptr, EDTSRC_I18N_OP_NAME);
+		WM_operator_properties_create_ptr(&ptr, ot);
 		RNA_string_set(&ptr, "lang", uilng);
 		RNA_string_set(&ptr, "po_file", popath);
 		RNA_string_set(&ptr, "but_label", but_label.strinfo);
@@ -743,7 +745,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
 		RNA_string_set(&ptr, "rna_prop", rna_prop.strinfo);
 		RNA_string_set(&ptr, "rna_enum", rna_enum.strinfo);
 		RNA_string_set(&ptr, "rna_ctxt", rna_ctxt.strinfo);
-		ret = WM_operator_name_call(C, EDTSRC_I18N_OP_NAME, WM_OP_INVOKE_DEFAULT, &ptr);
+		ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
 
 		/* Clean up */
 		if (but_label.strinfo)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 243aa45..7e0aad0 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -3188,7 +3188,7 @@ static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
 	wmOperatorType *ot = arg2;
 	
 	if (ot)
-		WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
+		WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, NULL);
 }
 
 static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 1d3013b..27d6fab 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1277,8 +1277,9 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN
 			const char *lastdir = folderlist_peeklastdir(sfile->folders_prev);
 
 			/* if not, ask to create it and enter if confirmed */
+			wmOperatorType *ot = WM_operatortype_find("FILE_OT_directory_new", false);
 			PointerRNA ptr;
-			WM_operator_properties_create(&ptr, "FILE_OT_directory_new");
+			WM_operator_properties_create_ptr(&ptr, ot);
 			RNA_string_set(&ptr, "directory", sfile->params->dir);
 			RNA_boolean_set(&ptr, "open", true);
 
@@ -1286,7 +1287,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN
 				BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir));
 
 
-			WM_operator_name_call(C, "FILE_OT_directory_new", WM_OP_INVOKE_DEFAULT, &ptr);
+			WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
 			WM_operator_properties_free(&ptr);
 		}
 
diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c
index 6978956..8fad17e 100644
--- a/source/blender/editors/space_file/file_panels.c
+++ b/source/blender/editors/space_file/file_panels.c
@@ -57,12 +57,13 @@
 
 static void file_panel_cb(bContext *C, void *arg_entry, void *UNUSED(arg_v))
 {
+	wmOperatorType *ot = WM_operatortype_find("FILE_OT_select_bookmark", false);
 	PointerRNA ptr;
 	const char *entry = (char *)arg_entry;
 
-	WM_operator_properties_create(&ptr, "FILE_OT_select_bookmark");
+	WM_operator_properties_create_ptr(&ptr, ot);
 	RNA_string_set(&ptr, "dir", entry);
-	WM_operator_name_call(C, "FILE_OT_select_bookmark", WM_OP_INVOKE_REGION_WIN, &ptr);
+	WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_REGION_WIN, &ptr);
 	WM_operator_properties_free(&ptr);
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 32f063d..f61f58c 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1147,11 +1147,12 @@ static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, unsigned int
 		}
 
 		{
+			wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_select_menu", false);
 			PointerRNA ptr;
 
-			WM_operator_properties_create(&ptr, "VIEW3D_OT_select_menu");
+			WM_operator_properties_create_ptr(&ptr, ot);
 			RNA_boolean_set(&ptr, "toggle", toggle);
-			WM_operator_name_call(C, "VIEW3D_OT_select_menu", WM_OP_INVOKE_DEFAULT, &ptr);
+			WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
 			WM_operator_properties_free(&ptr);
 		}
 
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 9886d40..c9d83a0 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -241,7 +241,8 @@ int			WM_operator_call		(struct bContext *C, struct wmOperator *op);
 int			WM_operator_call_notest(struct bContext *C, struct wmOperator *op);
 int			WM_operator_repeat		(struct bContext *C, struct wmOperator *op);
 bool        WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op);
-int			WM_operator_name_call	(struct bContext *C, const char *opstring, short context, struct PointerRNA *properties);
+int         WM_operator_name_call_ptr(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties);
+int			WM_operator_name_call(struct bContext *C, const char *opstring, short context, struct PointerRNA *properties);
 int			WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, const bool is_undo);
 
 void		WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 4b2ec0e..03f682a 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1261,11 +1261,17 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA
 
 
 /* invokes operator in context */
+int WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, short context, PointerRNA *properties)
+{
+	BLI_assert(ot == WM_operatortype_find(ot->idname, true));
+	return wm_operator_call_internal(C, ot, properties, NULL, context, false);
+}
 int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
 {
 	wmOperatorType *ot = WM_operatortype_find(opstring, 0);
-	if (ot)
-		return wm_operator_call_internal(C, ot, properties, NULL, context, false);
+	if (ot) {
+		return WM_operator_name_call_ptr(C, ot, context, properties);
+	}
 
 	return 0;
 }
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 8640c0a..b30fadd 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -974,14 +974,15 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
 				const char *path = GHOST_GetEventData(evt);
 				
 				if (path) {
+					wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
 					/* operator needs a valid window in context, ensures
 					 * it is correctly set */
 					oldWindow = CTX_wm_window(C);
 					CTX_wm_window_set(C, win);
 					
-					WM_operator_properties_create(&props_ptr, "WM_OT_open_mainfile");
+					WM_operator_properties_create_ptr(&props_ptr, ot);
 					RNA_string_set(&props_ptr, "filepath", path);
-					WM_operator_name_call(C, "WM_OT_open_mainfile", WM_OP_EXEC_DEFAULT, &props_ptr);
+					WM_operat

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list