From 7f3601e70dd094b6f9162bb03a8a3440d50de47e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 28 Dec 2020 17:37:16 +0100 Subject: Cleanup/refactor `rna_idp_path` code. Factorize common processes and checks, early `continue` in invalid cases, etc. --- source/blender/makesrna/intern/rna_access.c | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'source/blender/makesrna/intern/rna_access.c') diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 0b7ebb17d87..9411acaef64 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -5696,8 +5696,7 @@ static char *rna_idp_path(PointerRNA *ptr, BLI_assert(haystack->type == IDP_GROUP); link.up = parent_link; - /* always set both name and index, - * else a stale value might get used */ + /* Always set both name and index, else a stale value might get used. */ link.name = NULL; link.index = -1; @@ -5708,19 +5707,28 @@ static char *rna_idp_path(PointerRNA *ptr, path = rna_idp_path_create(&link); break; } + + /* Early out in case the IDProperty type cannot contain RNA properties. */ + if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) { + continue; + } + + /* Ensure this is RNA. */ + /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name + * collides with an actual fully static RNA property of the same struct (which would then not + * be flagged with `PROP_IDPROPERTY`). + * + * That case must be ignored here, we only want to deal with runtime RNA properties stored in + * IDProps. + * + * See T84091. */ + PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name); + if (prop == NULL || (prop->flag & PROP_IDPROPERTY) == 0) { + continue; + } + if (iter->type == IDP_GROUP) { - /* Ensure this is RNA. */ - PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name); - - /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name - * collides with an actual fully static RNA property of the same struct (which would then not - * be flagged with `PROP_IDPROPERTY`). - * - * That case must be ignored here, we only want to deal with runtime RNA properties stored in - * IDProps here. - * - * See T84091. */ - if (prop != NULL && prop->type == PROP_POINTER && (prop->flag & PROP_IDPROPERTY) != 0) { + if (prop->type == PROP_POINTER) { PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop); BLI_assert(child_ptr.type != NULL); link.name = iter->name; @@ -5731,9 +5739,7 @@ static char *rna_idp_path(PointerRNA *ptr, } } else if (iter->type == IDP_IDPARRAY) { - PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name); - /* See comment above in `IDP_GROUP` case, same applies here. */ - if (prop != NULL && prop->type == PROP_COLLECTION && (prop->flag & PROP_IDPROPERTY) != 0) { + if (prop->type == PROP_COLLECTION) { IDProperty *array = IDP_IDPArray(iter); if (needle >= array && needle < (iter->len + array)) { /* found! */ link.name = iter->name; -- cgit v1.2.3