Cleanup: Add check whether to remove an anonymous atttribute

Add a higher level check that can be used instead of checking whether
the attribute ID is anonymous and checking whether it has any strong
references.
This commit is contained in:
Hans Goudey 2021-10-20 09:57:54 -05:00
parent 494c3fb1bd
commit 990b912fd7
3 changed files with 17 additions and 11 deletions

View File

@ -55,6 +55,7 @@ class AttributeIDRef {
bool is_anonymous() const;
StringRef name() const;
const AnonymousAttributeID &anonymous_id() const;
bool should_be_kept() const;
friend bool operator==(const AttributeIDRef &a, const AttributeIDRef &b);
friend std::ostream &operator<<(std::ostream &stream, const AttributeIDRef &attribute_id);
@ -438,6 +439,16 @@ inline const AnonymousAttributeID &AttributeIDRef::anonymous_id() const
return *anonymous_id_;
}
/**
* \return True if the attribute should not be removed automatically as an optimization during
* processing or copying. Anonymous attributes can be removed when they no longer have any
* references.
*/
inline bool AttributeIDRef::should_be_kept() const
{
return this->is_named() || BKE_anonymous_attribute_id_has_strong_references(anonymous_id_);
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -507,12 +507,11 @@ void GeometrySet::gather_attributes_for_propagation(
return;
}
}
if (attribute_id.is_anonymous()) {
if (!BKE_anonymous_attribute_id_has_strong_references(&attribute_id.anonymous_id())) {
/* Don't propagate anonymous attributes that are not used anymore. */
return;
}
if (!attribute_id.should_be_kept()) {
return;
}
auto add_info = [&](AttributeKind *attribute_kind) {
attribute_kind->domain = meta_data.domain;
attribute_kind->data_type = meta_data.data_type;

View File

@ -78,12 +78,8 @@ static void copy_attributes_to_points(CurveEval &curve,
continue;
}
/* Don't copy anonymous attributes with no references anymore. */
if (attribute_id.is_anonymous()) {
const AnonymousAttributeID &anonymous_id = attribute_id.anonymous_id();
if (!BKE_anonymous_attribute_id_has_strong_references(&anonymous_id)) {
continue;
}
if (!attribute_id.should_be_kept()) {
continue;
}
const fn::GVArrayPtr mesh_attribute = mesh_component.attribute_try_get_for_read(