[Bf-blender-cvs] [bb0e0fde324] temp-geometry-nodes-fields-prototype: cleanup

Jacques Lucke noreply at git.blender.org
Wed Jul 28 14:14:20 CEST 2021


Commit: bb0e0fde324b7b793e7bac6c597083b96bc03b6d
Author: Jacques Lucke
Date:   Mon Jul 26 17:17:23 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rBbb0e0fde324b7b793e7bac6c597083b96bc03b6d

cleanup

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

M	source/blender/blenkernel/BKE_field.hh
M	source/blender/functions/FN_generic_virtual_array.hh

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

diff --git a/source/blender/blenkernel/BKE_field.hh b/source/blender/blenkernel/BKE_field.hh
index 42b05abd846..83435ad8236 100644
--- a/source/blender/blenkernel/BKE_field.hh
+++ b/source/blender/blenkernel/BKE_field.hh
@@ -229,13 +229,8 @@ template<typename T> class Field : public GField {
   GFieldOutput evaluate_generic(IndexMask mask, const FieldInputs &inputs) const override
   {
     FieldOutput<T> output = this->evaluate(mask, inputs);
-    optional_ptr<const VArray<T>> varray = output.extract();
-    if (varray.is_owned()) {
-      return GFieldOutput{optional_ptr<const GVArray>{
-          std::make_unique<fn::GVArray_For_OwnedVArray<T>>(varray.extract_owned())}};
-    }
-    return GFieldOutput{
-        optional_ptr<const GVArray>{std::make_unique<fn::GVArray_For_VArray<T>>(output.varray())}};
+    return optional_ptr<const GVArray>{
+        std::make_unique<fn::GVArray_For_VArray<T>>(output.extract().extract_owned())};
   }
 
   const CPPType &output_type() const override
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index b6b738987e7..dbb66ea8834 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -25,6 +25,7 @@
 
 #include <optional>
 
+#include "BLI_optional_ptr.hh"
 #include "BLI_virtual_array.hh"
 
 #include "FN_generic_span.hh"
@@ -356,11 +357,16 @@ class GVArray_For_SingleValue : public GVArray_For_SingleValueRef {
 /* Used to convert a typed virtual array into a generic one. */
 template<typename T> class GVArray_For_VArray : public GVArray {
  protected:
-  const VArray<T> *varray_ = nullptr;
+  optional_ptr<const VArray<T>> varray_;
 
  public:
   GVArray_For_VArray(const VArray<T> &varray)
-      : GVArray(CPPType::get<T>(), varray.size()), varray_(&varray)
+      : GVArray(CPPType::get<T>(), varray.size()), varray_(varray)
+  {
+  }
+
+  GVArray_For_VArray(optional_ptr<const VArray<T>> varray)
+      : GVArray(CPPType::get<T>(), varray->size()), varray_(std::move(varray))
   {
   }
 
@@ -411,7 +417,7 @@ template<typename T> class GVArray_For_VArray : public GVArray {
 
   const void *try_get_internal_varray_impl() const override
   {
-    return varray_;
+    return &*varray_;
   }
 };
 
@@ -646,18 +652,6 @@ template<typename T> class GVArray_Span : public Span<T> {
   }
 };
 
-template<typename T> class GVArray_For_OwnedVArray : public GVArray_For_VArray<T> {
- private:
-  VArrayPtr<T> owned_varray_;
-
- public:
-  /* Takes ownership of varray and passes a reference to the base class. */
-  GVArray_For_OwnedVArray(VArrayPtr<T> varray)
-      : GVArray_For_VArray<T>(*varray), owned_varray_(std::move(varray))
-  {
-  }
-};
-
 template<typename T> class VArray_For_OwnedGVArray : public VArray_For_GVArray<T> {
  private:
   GVArrayPtr owned_varray_;
@@ -708,7 +702,7 @@ class GVArray_For_EmbeddedVArray : public GVArray_For_VArray<T> {
   GVArray_For_EmbeddedVArray(const int64_t size, Args &&... args)
       : GVArray_For_VArray<T>(size), embedded_varray_(std::forward<Args>(args)...)
   {
-    this->varray_ = &embedded_varray_;
+    this->varray_ = embedded_varray_;
   }
 };



More information about the Bf-blender-cvs mailing list