[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43304] trunk/blender/source/blender: add RNA_property_is_set function, use for WM_menu_invoke to avoid double lookup and py api to de-duplicate some checks

Campbell Barton ideasman42 at gmail.com
Wed Jan 11 17:48:25 CET 2012


Revision: 43304
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43304
Author:   campbellbarton
Date:     2012-01-11 16:48:22 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
add RNA_property_is_set function, use for WM_menu_invoke to avoid double lookup and py api to de-duplicate some checks

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2012-01-11 16:32:12 UTC (rev 43303)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2012-01-11 16:48:22 UTC (rev 43304)
@@ -933,7 +933,8 @@
 	}
 
 /* check if the idproperty exists, for operators */
-int RNA_struct_property_is_set(PointerRNA *ptr, const char *name);
+int RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop);
+int RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier);
 int RNA_property_is_idprop(PropertyRNA *prop);
 
 /* python compatible string representation of this property, (must be freed!) */

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-01-11 16:32:12 UTC (rev 43303)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-01-11 16:48:22 UTC (rev 43304)
@@ -4412,15 +4412,22 @@
 	}
 }
 
-int RNA_struct_property_is_set(PointerRNA *ptr, const char *name)
+int RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
 {
-	PropertyRNA *prop= RNA_struct_find_property(ptr, name);
+	if(prop->flag & PROP_IDPROPERTY) {
+		return (rna_idproperty_find(ptr, prop->identifier) != NULL);
+	}
+	else {
+		return 1;
+	}
+}
 
+int RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
+{
+	PropertyRNA *prop= RNA_struct_find_property(ptr, identifier);
+
 	if(prop) {
-		if(prop->flag & PROP_IDPROPERTY)
-			return (rna_idproperty_find(ptr, name) != NULL);
-		else
-			return 1;
+		return RNA_property_is_set(ptr, prop);
 	}
 	else {
 		/* python raises an error */

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2012-01-11 16:32:12 UTC (rev 43303)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-01-11 16:48:22 UTC (rev 43304)
@@ -3055,7 +3055,6 @@
 {
 	PropertyRNA *prop;
 	const char *name;
-	int ret;
 
 	PYRNA_STRUCT_CHECK_OBJ(self);
 
@@ -3069,22 +3068,7 @@
 		return NULL;
 	}
 
-	/* double property lookup, could speed up */
-	/* return PyBool_FromLong(RNA_struct_property_is_set(&self->ptr, name)); */
-	if (RNA_property_flag(prop) & PROP_IDPROPERTY) {
-		IDProperty *group = RNA_struct_idprops(&self->ptr, 0);
-		if (group) {
-			ret = IDP_GetPropertyFromGroup(group, name) ? 1:0;
-		}
-		else {
-			ret = 0;
-		}
-	}
-	else {
-		ret = 1;
-	}
-
-	return PyBool_FromLong(ret);
+	return PyBool_FromLong(RNA_property_is_set(&self->ptr, prop));
 }
 
 PyDoc_STRVAR(pyrna_struct_is_property_hidden_doc,

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-01-11 16:32:12 UTC (rev 43303)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-01-11 16:48:22 UTC (rev 43304)
@@ -665,7 +665,7 @@
 		printf("%s: %s \"%s\" is not an enum property\n",
 		       __func__, op->type->idname, RNA_property_identifier(prop));
 	}
-	else if (RNA_struct_property_is_set(op->ptr, RNA_property_identifier(prop))) {
+	else if (RNA_property_is_set(op->ptr, prop)) {
 		const int retval= op->type->exec(C, op);
 		OPERATOR_RETVAL_CHECK(retval);
 		return retval;



More information about the Bf-blender-cvs mailing list