[Bf-blender-cvs] [0998856c923] master: Cleanup: use movable output attribute instead of optional

Jacques Lucke noreply at git.blender.org
Sun Oct 3 15:01:11 CEST 2021


Commit: 0998856c923f28b1cf2199b945e3eb70cbface96
Author: Jacques Lucke
Date:   Sun Oct 3 15:01:02 2021 +0200
Branches: master
https://developer.blender.org/rB0998856c923f28b1cf2199b945e3eb70cbface96

Cleanup: use movable output attribute instead of optional

This simplifies the code a bit and improves compile times a bit.

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 25ee4d3c132..ef43e21b739 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -248,6 +248,7 @@ template<typename T> class OutputAttribute_Typed {
   VMutableArray<T> *varray_ = nullptr;
 
  public:
+  OutputAttribute_Typed() = default;
   OutputAttribute_Typed(OutputAttribute attribute) : attribute_(std::move(attribute))
   {
     if (attribute_) {
@@ -259,6 +260,16 @@ template<typename T> class OutputAttribute_Typed {
   OutputAttribute_Typed(OutputAttribute_Typed &&other) = default;
   ~OutputAttribute_Typed() = default;
 
+  OutputAttribute_Typed &operator=(OutputAttribute_Typed &&other)
+  {
+    if (this == &other) {
+      return *this;
+    }
+    this->~OutputAttribute_Typed();
+    new (this) OutputAttribute_Typed(std::move(other));
+    return *this;
+  }
+
   operator bool() const
   {
     return varray_ != nullptr;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
index 1a4c5d84dbf..0c8db0d8912 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
@@ -331,28 +331,28 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com
                                                    const Span<int> looptri_indices,
                                                    const AttributeOutputs &attribute_outputs)
 {
-  std::optional<OutputAttribute_Typed<int>> id_attribute;
-  std::optional<OutputAttribute_Typed<float3>> normal_attribute;
-  std::optional<OutputAttribute_Typed<float3>> rotation_attribute;
+  OutputAttribute_Typed<int> id_attribute;
+  OutputAttribute_Typed<float3> normal_attribute;
+  OutputAttribute_Typed<float3> rotation_attribute;
 
   MutableSpan<int> ids;
   MutableSpan<float3> normals;
   MutableSpan<float3> rotations;
 
   if (attribute_outputs.stable_id_id) {
-    id_attribute.emplace(point_component.attribute_try_get_for_output_only<int>(
-        attribute_outputs.stable_id_id.get(), ATTR_DOMAIN_POINT));
-    ids = id_attribute->as_span();
+    id_attribute = point_component.attribute_try_get_for_output_only<int>(
+        attribute_outputs.stable_id_id.get(), ATTR_DOMAIN_POINT);
+    ids = id_attribute.as_span();
   }
   if (attribute_outputs.normal_id) {
-    normal_attribute.emplace(point_component.attribute_try_get_for_output_only<float3>(
-        attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT));
-    normals = normal_attribute->as_span();
+    normal_attribute = point_component.attribute_try_get_for_output_only<float3>(
+        attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT);
+    normals = normal_attribute.as_span();
   }
   if (attribute_outputs.rotation_id) {
-    rotation_attribute.emplace(point_component.attribute_try_get_for_output_only<float3>(
-        attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT));
-    rotations = rotation_attribute->as_span();
+    rotation_attribute = point_component.attribute_try_get_for_output_only<float3>(
+        attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT);
+    rotations = rotation_attribute.as_span();
   }
 
   const Mesh &mesh = *mesh_component.get_for_read();
@@ -387,13 +387,13 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com
   }
 
   if (id_attribute) {
-    id_attribute->save();
+    id_attribute.save();
   }
   if (normal_attribute) {
-    normal_attribute->save();
+    normal_attribute.save();
   }
   if (rotation_attribute) {
-    rotation_attribute->save();
+    rotation_attribute.save();
   }
 }



More information about the Bf-blender-cvs mailing list