RNA: add RNA_collection_is_empty & RNA_property_collection_is_empty

Some collections needed to be iterated over to count their length.
Provide a function to check if the collection is empty to avoid this.
This commit is contained in:
2022-02-15 20:07:54 +11:00
parent 4637e83990
commit 07ed869b94
7 changed files with 36 additions and 14 deletions

View File

@@ -2192,16 +2192,9 @@ static int pyrna_prop_array_bool(BPy_PropertyRNA *self)
static int pyrna_prop_collection_bool(BPy_PropertyRNA *self)
{
/* No callback defined, just iterate and find the nth item. */
CollectionPropertyIterator iter;
int test;
PYRNA_PROP_CHECK_INT(self);
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
test = iter.valid;
RNA_property_collection_end(&iter);
return test;
return !RNA_property_collection_is_empty(&self->ptr, self->prop);
}
/* notice getting the length of the collection is avoided unless negative