[Bf-blender-cvs] [633f1cdec97] master: Cleanup: improve gathering supported domains by geometry type

Jacques Lucke noreply at git.blender.org
Wed Mar 17 11:53:13 CET 2021


Commit: 633f1cdec970d7f4c348ff63f4e8ef1bc8dfc2df
Author: Jacques Lucke
Date:   Wed Mar 17 11:50:13 2021 +0100
Branches: master
https://developer.blender.org/rB633f1cdec970d7f4c348ff63f4e8ef1bc8dfc2df

Cleanup: improve gathering supported domains by geometry type

===================================================================

M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/attribute_access_intern.hh
M	source/blender/blenkernel/intern/geometry_component_mesh.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 8482f096df1..91b5b01e3eb 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -674,9 +674,10 @@ bool NamedLegacyCustomDataProvider::foreach_attribute(
   return true;
 }
 
-void NamedLegacyCustomDataProvider::supported_domains(Vector<AttributeDomain> &r_domains) const
+void NamedLegacyCustomDataProvider::foreach_domain(
+    const FunctionRef<void(AttributeDomain)> callback) const
 {
-  r_domains.append_non_duplicates(domain_);
+  callback(domain_);
 }
 
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/attribute_access_intern.hh b/source/blender/blenkernel/intern/attribute_access_intern.hh
index 19349c69662..a6fd49bb0c6 100644
--- a/source/blender/blenkernel/intern/attribute_access_intern.hh
+++ b/source/blender/blenkernel/intern/attribute_access_intern.hh
@@ -18,6 +18,9 @@
 #include "BLI_span.hh"
 #include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
+#include "BLI_vector_set.hh"
+
+#include "BKE_geometry_set.hh"
 
 namespace blender::bke {
 
@@ -286,7 +289,7 @@ class DynamicAttributesProvider {
 
   virtual bool foreach_attribute(const GeometryComponent &component,
                                  const AttributeForeachCallback callback) const = 0;
-  virtual void supported_domains(blender::Vector<AttributeDomain> &r_domains) const = 0;
+  virtual void foreach_domain(const FunctionRef<void(AttributeDomain)> callback) const = 0;
 };
 
 /**
@@ -324,9 +327,9 @@ class CustomDataAttributeProvider final : public DynamicAttributesProvider {
   bool foreach_attribute(const GeometryComponent &component,
                          const AttributeForeachCallback callback) const final;
 
-  void supported_domains(blender::Vector<AttributeDomain> &r_domains) const final
+  void foreach_domain(const FunctionRef<void(AttributeDomain)> callback) const final
   {
-    r_domains.append_non_duplicates(domain_);
+    callback(domain_);
   }
 
  private:
@@ -388,7 +391,7 @@ class NamedLegacyCustomDataProvider final : public DynamicAttributesProvider {
   bool try_delete(GeometryComponent &component, const StringRef attribute_name) const final;
   bool foreach_attribute(const GeometryComponent &component,
                          const AttributeForeachCallback callback) const final;
-  void supported_domains(Vector<AttributeDomain> &r_domains) const final;
+  void foreach_domain(const FunctionRef<void(AttributeDomain)> callback) const final;
 };
 
 /**
@@ -457,7 +460,7 @@ class ComponentAttributeProviders {
   /**
    * All the domains that are supported by at least one of the providers above.
    */
-  blender::Vector<AttributeDomain> supported_domains_;
+  blender::VectorSet<AttributeDomain> supported_domains_;
 
  public:
   ComponentAttributeProviders(
@@ -465,14 +468,13 @@ class ComponentAttributeProviders {
       blender::Span<const DynamicAttributesProvider *> dynamic_attribute_providers)
       : dynamic_attribute_providers_(dynamic_attribute_providers)
   {
-    blender::Set<AttributeDomain> domains;
     for (const BuiltinAttributeProvider *provider : builtin_attribute_providers) {
       /* Use #add_new to make sure that no two builtin attributes have the same name. */
       builtin_attribute_providers_.add_new(provider->name(), provider);
-      supported_domains_.append_non_duplicates(provider->domain());
+      supported_domains_.add(provider->domain());
     }
     for (const DynamicAttributesProvider *provider : dynamic_attribute_providers) {
-      provider->supported_domains(supported_domains_);
+      provider->foreach_domain([&](AttributeDomain domain) { supported_domains_.add(domain); });
     }
   }
 
@@ -493,4 +495,4 @@ class ComponentAttributeProviders {
   }
 };
 
-}  // namespace blender::bke
\ No newline at end of file
+}  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index b376a9dd083..8ee2142799d 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -782,9 +782,9 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
     return true;
   }
 
-  void supported_domains(Vector<AttributeDomain> &r_domains) const final
+  void foreach_domain(const FunctionRef<void(AttributeDomain)> callback) const final
   {
-    r_domains.append_non_duplicates(ATTR_DOMAIN_POINT);
+    callback(ATTR_DOMAIN_POINT);
   }
 };



More information about the Bf-blender-cvs mailing list