diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-11 20:48:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-11 20:48:22 +0400 |
commit | 02560d748f454b87f756908268f0a2c6bdde934a (patch) | |
tree | c9d8930e7fc77c795f27d2bd67d3d6284b08eeda /source | |
parent | f66f33cefcdd3ff5be2c3940aa494bd52a75d074 (diff) |
add RNA_property_is_set function, use for WM_menu_invoke to avoid double lookup and py api to de-duplicate some checks
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 19 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 18 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 |
4 files changed, 17 insertions, 25 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 7e8ea11a940..9c8cd831d72 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -933,7 +933,8 @@ void RNA_collection_clear(PointerRNA *ptr, const char *name); } /* 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!) */ diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 41641af6514..ddd0fa1434c 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4412,15 +4412,22 @@ int RNA_collection_length(PointerRNA *ptr, const char *name) } } -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 */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index a54e65011e6..588f08224c8 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -3055,7 +3055,6 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg { PropertyRNA *prop; const char *name; - int ret; PYRNA_STRUCT_CHECK_OBJ(self); @@ -3069,22 +3068,7 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg 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, diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 19050208265..c917031708d 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -665,7 +665,7 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 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; |