[Bf-blender-cvs] [45619f2f2f8] functions: cleanup

Jacques Lucke noreply at git.blender.org
Mon Jan 27 22:10:28 CET 2020


Commit: 45619f2f2f8b1ff9259544bd2c23b9817d634b92
Author: Jacques Lucke
Date:   Mon Jan 27 15:40:24 2020 +0100
Branches: functions
https://developer.blender.org/rB45619f2f2f8b1ff9259544bd2c23b9817d634b92

cleanup

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

M	source/blender/functions/FN_multi_function_network.h
M	source/blender/functions/intern/multi_functions/network.cc

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

diff --git a/source/blender/functions/FN_multi_function_network.h b/source/blender/functions/FN_multi_function_network.h
index 56a9016b8af..fd45ce3ff12 100644
--- a/source/blender/functions/FN_multi_function_network.h
+++ b/source/blender/functions/FN_multi_function_network.h
@@ -365,6 +365,7 @@ class MFOutputSocket final : public MFSocket {
 
  public:
   ArrayRef<const MFInputSocket *> targets() const;
+  uint target_amount() const;
 };
 
 class MFNetwork : BLI::NonCopyable, BLI::NonMovable {
@@ -785,6 +786,11 @@ inline ArrayRef<const MFInputSocket *> MFOutputSocket::targets() const
   return m_targets;
 }
 
+inline uint MFOutputSocket::target_amount() const
+{
+  return m_targets.size();
+}
+
 inline const MFNode &MFNetwork::node_by_id(uint index) const
 {
   return *m_node_by_id[index];
diff --git a/source/blender/functions/intern/multi_functions/network.cc b/source/blender/functions/intern/multi_functions/network.cc
index b27a842e562..0952a729af6 100644
--- a/source/blender/functions/intern/multi_functions/network.cc
+++ b/source/blender/functions/intern/multi_functions/network.cc
@@ -18,30 +18,59 @@ enum Enum {
 
 struct OutputValue {
   OutputValueType::Enum type;
+
+  OutputValue(OutputValueType::Enum type) : type(type)
+  {
+  }
 };
 
 struct SingleFromCallerValue : public OutputValue {
   GenericVirtualListRef list_ref;
+
+  SingleFromCallerValue(GenericVirtualListRef list_ref)
+      : OutputValue(OutputValueType::SingleFromCaller), list_ref(list_ref)
+  {
+  }
 };
 
 struct VectorFromCallerValue : public OutputValue {
   GenericVirtualListListRef list_list_ref;
+
+  VectorFromCallerValue(GenericVirtualListListRef list_list_ref)
+      : OutputValue(OutputValueType::VectorFromCaller), list_list_ref(list_list_ref)
+  {
+  }
 };
 
 struct SingleValue : public OutputValue {
   GenericMutableArrayRef array_ref;
   int max_remaining_users;
   bool is_single_allocated;
+
+  SingleValue(GenericMutableArrayRef array_ref, int max_remaining_users, bool is_single_allocated)
+      : OutputValue(OutputValueType::Single),
+        array_ref(array_ref),
+        max_remaining_users(max_remaining_users),
+        is_single_allocated(is_single_allocated)
+  {
+  }
 };
 
 struct VectorValue : public OutputValue {
   GenericVectorArray *vector_array;
   int max_remaining_users;
+
+  VectorValue(GenericVectorArray &vector_array, int max_remaining_users)
+      : OutputValue(OutputValueType::Vector),
+        vector_array(&vector_array),
+        max_remaining_users(max_remaining_users)
+  {
+  }
 };
 
 class NetworkEvaluationStorage {
  private:
-  MonotonicAllocator<256> m_monotonic_allocator;
+  MonotonicAllocator<256> m_allocator;
   ArrayAllocator &m_array_allocator;
   IndexMask m_mask;
   Array<OutputValue *> m_value_per_output_id;
@@ -92,10 +121,8 @@ class NetworkEvaluationStorage {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
     BLI_assert(list_ref.size() >= m_min_array_size);
 
-    auto *value = m_monotonic_allocator.allocate<SingleFromCallerValue>();
+    auto *value = m_allocator.construct<SingleFromCallerValue>(list_ref).release();
     m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::SingleFromCaller;
-    value->list_ref = list_ref;
   }
 
   void add_vector_from_caller(const MFOutputSocket &socket,
@@ -104,42 +131,36 @@ class NetworkEvaluationStorage {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
     BLI_assert(list_list_ref.size() >= m_min_array_size);
 
-    auto *value = m_monotonic_allocator.allocate<VectorFromCallerValue>();
+    auto *value = m_allocator.construct<VectorFromCallerValue>(list_list_ref).release();
     m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::VectorFromCaller;
-    value->list_list_ref = list_list_ref;
   }
 
   GenericMutableArrayRef allocate_single_output(const MFOutputSocket &socket)
   {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
 
-    auto *value = m_monotonic_allocator.allocate<SingleValue>();
-    m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::Single;
-    value->max_remaining_users = socket.targets().size();
-    value->is_single_allocated = false;
-
     const CPPType &type = socket.data_type().single__cpp_type();
     void *buffer = m_array_allocator.allocate(type.size(), type.alignment());
-    value->array_ref = GenericMutableArrayRef(type, buffer, m_min_array_size);
+    GenericMutableArrayRef array_ref(type, buffer, m_min_array_size);
 
-    return value->array_ref;
+    auto *value =
+        m_allocator.construct<SingleValue>(array_ref, socket.target_amount(), false).release();
+    m_value_per_output_id[socket.id()] = value;
+
+    return array_ref;
   }
 
   GenericMutableArrayRef allocate_single_output__scalar(const MFOutputSocket &socket)
   {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
 
-    auto *value = m_monotonic_allocator.allocate<SingleValue>();
-    m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::Single;
-    value->max_remaining_users = socket.targets().size();
-    value->is_single_allocated = true;
-
     const CPPType &type = socket.data_type().single__cpp_type();
-    void *buffer = m_monotonic_allocator.allocate(type.size(), type.alignment());
-    value->array_ref = GenericMutableArrayRef(type, buffer, 1);
+    void *buffer = m_allocator.allocate(type.size(), type.alignment());
+    GenericMutableArrayRef array_ref(type, buffer, 1);
+
+    auto *value =
+        m_allocator.construct<SingleValue>(array_ref, socket.target_amount(), true).release();
+    m_value_per_output_id[socket.id()] = value;
 
     return value->array_ref;
   }
@@ -148,14 +169,12 @@ class NetworkEvaluationStorage {
   {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
 
-    auto *value = m_monotonic_allocator.allocate<VectorValue>();
-    m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::Vector;
-    value->max_remaining_users = socket.targets().size();
-
     const CPPType &type = socket.data_type().vector__cpp_base_type();
     GenericVectorArray *vector_array = new GenericVectorArray(type, m_min_array_size);
-    value->vector_array = vector_array;
+
+    auto *value =
+        m_allocator.construct<VectorValue>(*vector_array, socket.target_amount()).release();
+    m_value_per_output_id[socket.id()] = value;
 
     return *value->vector_array;
   }
@@ -164,14 +183,12 @@ class NetworkEvaluationStorage {
   {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
 
-    auto *value = m_monotonic_allocator.allocate<VectorValue>();
-    m_value_per_output_id[socket.id()] = value;
-    value->type = OutputValueType::Vector;
-    value->max_remaining_users = socket.targets().size();
-
     const CPPType &type = socket.data_type().vector__cpp_base_type();
     GenericVectorArray *vector_array = new GenericVectorArray(type, 1);
-    value->vector_array = vector_array;
+
+    auto *value =
+        m_allocator.construct<VectorValue>(*vector_array, socket.target_amount()).release();
+    m_value_per_output_id[socket.id()] = value;
 
     return *value->vector_array;
   }
@@ -191,35 +208,34 @@ class NetworkEvaluationStorage {
       if (value->max_remaining_users == 1) {
         m_value_per_output_id[to.id()] = value;
         m_value_per_output_id[from.id()] = nullptr;
-        value->max_remaining_users = to.targets().size();
+        value->max_remaining_users = to.target_amount();
         return value->array_ref;
       }
       else {
-        SingleValue *new_value = m_monotonic_allocator.allocate<SingleValue>();
-        m_value_per_output_id[to.id()] = new_value;
-        new_value->type = OutputValueType::Single;
-        new_value->max_remaining_users = to.targets().size();
-        new_value->is_single_allocated = false;
-
         const CPPType &type = from.data_type().single__cpp_type();
         void *new_buffer = m_array_allocator.allocate(type.size(), type.alignment());
         type.copy_to_uninitialized_indices(value->array_ref.buffer(), new_buffer, m_mask);
-        new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_min_array_size);
-        return new_value->array_ref;
+        GenericMutableArrayRef new_array_ref(type, new_buffer, m_min_array_size);
+
+        SingleValue *new_value =
+            m_allocator.construct<SingleValue>(new_array_ref, to.target_amount(), false).release();
+        m_value_per_output_id[to.id()] = new_value;
+
+        return new_array_ref;
       }
     }
     else if (any_value->type == OutputValueType::SingleFromCaller) {
       SingleFromCallerValue *value = (SingleFromCallerValue *)any_value;
-      SingleValue *new_value = m_monotonic_allocator.allocate<SingleValue>();
-      m_value_per_output_id[to.id()] = new_value;
-      new_value->type = OutputValueType::Single;
-      new_value->max_remaining_users = to.targets().size();
-      new_value->is_single_allocated = false;
 
       const CPPType &type = from.data_type().single__cpp_type();
       void *new_buffer = m_array_allocator.allocate(type.size(), type.alignment());
-      new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_min_array_size);
-      value->list_ref.materialize_to_uninitialized(m_mask, new_value->array_ref);
+      GenericMutableArrayRef new_array_ref(type, new_buffer, m_min_array_size);
+      value->list_ref.materialize_to_uninitialized(m_mask, new_array_ref);
+
+      SingleValue *new_value =
+          m_allocator.construct<SingleValue>(new_array_ref, to.target_amount(), false).release();
+      m_value_per_output_id[to.id()] = new_value;
+
       return new_value->array_ref;
     }
 
@@ -242,36 +258,36 @@ class NetworkEvaluationStorage {
       if (value->max_remaining_users == 1) {
         m_value_per_output_id[to.id()] = value;
         m_value_per_output_id[from.id()] = nullptr;
-        value->max_remaining_users = to.targets().size();
+        value->max_remaining_users = to.target_amount();
         BLI_assert(value->array_ref.size() == 1);
         return value->array_ref;
       }
       else {
-        SingleValue *new_value = m_monotonic_allocator.allocate<SingleValue>();
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list