[Bf-blender-cvs] [59df9149836] functions-experimental-refactor: replace ArrayOrSingleRef with VirtualListRef

Jacques Lucke noreply at git.blender.org
Sun Oct 20 15:55:52 CEST 2019


Commit: 59df91498366cdd4429d579dd30549017fe8fc77
Author: Jacques Lucke
Date:   Sun Oct 20 15:55:33 2019 +0200
Branches: functions-experimental-refactor
https://developer.blender.org/rB59df91498366cdd4429d579dd30549017fe8fc77

replace ArrayOrSingleRef with VirtualListRef

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

M	source/blender/blenkernel/BKE_generic_array_ref.h
A	source/blender/blenkernel/BKE_generic_virtual_list_ref.h
M	source/blender/blenkernel/BKE_multi_function.h
M	source/blender/blenkernel/intern/multi_functions.cc
D	source/blender/blenlib/BLI_array_or_single_ref.h
M	source/blender/blenlib/BLI_virtual_list_ref.h

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

diff --git a/source/blender/blenkernel/BKE_generic_array_ref.h b/source/blender/blenkernel/BKE_generic_array_ref.h
index 4ab6b59ac7a..8d4372bf56e 100644
--- a/source/blender/blenkernel/BKE_generic_array_ref.h
+++ b/source/blender/blenkernel/BKE_generic_array_ref.h
@@ -5,11 +5,9 @@
 #include "BKE_cpp_types.h"
 
 #include "BLI_array_ref.h"
-#include "BLI_array_or_single_ref.h"
 
 namespace BKE {
 
-using BLI::ArrayOrSingleRef;
 using BLI::ArrayRef;
 using BLI::MutableArrayRef;
 
@@ -59,63 +57,6 @@ class GenericArrayRef {
   }
 };
 
-class GenericArrayOrSingleRef {
- private:
-  const CPPType *m_type;
-  const void *m_buffer;
-  uint m_array_size;
-  bool m_is_single;
-
- public:
-  GenericArrayOrSingleRef() = delete;
-
-  GenericArrayOrSingleRef(const CPPType &type, const void *buffer, uint array_size, bool is_single)
-      : m_type(&type), m_buffer(buffer), m_array_size(array_size), m_is_single(is_single)
-  {
-  }
-
-  GenericArrayOrSingleRef(const CPPType &type) : GenericArrayOrSingleRef(type, nullptr, 0, false)
-  {
-  }
-
-  static GenericArrayOrSingleRef FromSingle(const CPPType &type,
-                                            const void *buffer,
-                                            uint array_size)
-  {
-    return GenericArrayOrSingleRef(type, buffer, array_size, true);
-  }
-
-  static GenericArrayOrSingleRef FromArray(const CPPType &type,
-                                           const void *buffer,
-                                           uint array_size)
-  {
-    return GenericArrayOrSingleRef(type, buffer, array_size, false);
-  }
-
-  template<typename T> static GenericArrayOrSingleRef FromArray(ArrayRef<T> array)
-  {
-    return GenericArrayOrSingleRef::FromArray(
-        GET_TYPE<T>(), (const void *)array.begin(), array.size());
-  }
-
-  template<typename T> ArrayOrSingleRef<T> as_typed_ref() const
-  {
-    BLI_assert(GET_TYPE<T>().is_same_or_generalization(*m_type));
-    return ArrayOrSingleRef<T>((const T *)m_buffer, m_array_size, m_is_single);
-  }
-
-  const void *operator[](uint index) const
-  {
-    BLI_assert(index < m_array_size);
-    if (m_is_single) {
-      return m_buffer;
-    }
-    else {
-      return POINTER_OFFSET(m_buffer, index * m_type->size());
-    }
-  }
-};
-
 class GenericMutableArrayRef {
  private:
   const CPPType *m_type;
diff --git a/source/blender/blenkernel/BKE_generic_virtual_list_ref.h b/source/blender/blenkernel/BKE_generic_virtual_list_ref.h
new file mode 100644
index 00000000000..23f2bf69570
--- /dev/null
+++ b/source/blender/blenkernel/BKE_generic_virtual_list_ref.h
@@ -0,0 +1,124 @@
+#ifndef __BKE_GENERIC_VIRTUAL_LIST_REF_REF_H__
+#define __BKE_GENERIC_VIRTUAL_LIST_REF_REF_H__
+
+#include "BKE_cpp_types.h"
+
+#include "BLI_virtual_list_ref.h"
+
+namespace BKE {
+
+using BLI::ArrayRef;
+using BLI::VirtualListRef;
+
+class GenericVirtualListRef {
+ private:
+  enum Category {
+    Single,
+    FullArray,
+    RepeatedArray,
+  };
+
+  const CPPType *m_type;
+  uint m_virtual_size;
+  Category m_category;
+
+  union {
+    struct {
+      const void *data;
+    } single;
+    struct {
+      const void *data;
+    } full_array;
+    struct {
+      const void *data;
+      uint real_size;
+    } repeated_array;
+  } m_data;
+
+  GenericVirtualListRef() = default;
+
+ public:
+  static GenericVirtualListRef FromSingle(const CPPType &type,
+                                          const void *buffer,
+                                          uint virtual_size)
+  {
+    GenericVirtualListRef list;
+    list.m_virtual_size = virtual_size;
+    list.m_type = &type;
+    list.m_category = Single;
+    list.m_data.single.data = buffer;
+    return list;
+  }
+
+  static GenericVirtualListRef FromFullArray(const CPPType &type, const void *buffer, uint size)
+  {
+    GenericVirtualListRef list;
+    list.m_virtual_size = size;
+    list.m_type = &type;
+    list.m_category = FullArray;
+    list.m_data.full_array.data = buffer;
+    return list;
+  }
+
+  template<typename T> static GenericVirtualListRef FromFullArray(ArrayRef<T> array)
+  {
+    return GenericVirtualListRef::FromFullArray(
+        GET_TYPE<T>(), (const void *)array.begin(), array.size());
+  }
+
+  static GenericVirtualListRef FromRepeatedArray(const CPPType &type,
+                                                 const void *buffer,
+                                                 uint real_size,
+                                                 uint virtual_size)
+  {
+    GenericVirtualListRef list;
+    list.m_virtual_size = virtual_size;
+    list.m_type = &type;
+    list.m_category = RepeatedArray;
+    list.m_data.repeated_array.data = buffer;
+    list.m_data.repeated_array.real_size = real_size;
+    return list;
+  }
+
+  uint size() const
+  {
+    return m_virtual_size;
+  }
+
+  const void *operator[](uint index) const
+  {
+    BLI_assert(index < m_virtual_size);
+    switch (m_category) {
+      case Single:
+        return m_data.single.data;
+      case FullArray:
+        return POINTER_OFFSET(m_data.full_array.data, index * m_type->size());
+      case RepeatedArray:
+        uint real_index = index % m_data.repeated_array.real_size;
+        return POINTER_OFFSET(m_data.repeated_array.data, real_index * m_type->size());
+    }
+    BLI_assert(false);
+    return m_data.single.data;
+  }
+
+  template<typename T> VirtualListRef<T> as_typed_ref() const
+  {
+    BLI_assert(GET_TYPE<T>().is_same_or_generalization(*m_type));
+    switch (m_category) {
+      case Single:
+        return VirtualListRef<T>::FromSingle((const T *)m_data.single.data, m_virtual_size);
+      case FullArray:
+        return VirtualListRef<T>::FromFullArray((const T *)m_data.full_array.data, m_virtual_size);
+      case RepeatedArray:
+        return VirtualListRef<T>::FromRepeatedArray((const T *)m_data.repeated_array.data,
+                                                    m_data.repeated_array.real_size,
+                                                    m_virtual_size);
+    }
+    BLI_assert(false);
+    return {};
+  }
+};
+
+}  // namespace BKE
+
+#endif /* __BKE_GENERIC_VIRTUAL_LIST_REF_REF_H__ */
diff --git a/source/blender/blenkernel/BKE_multi_function.h b/source/blender/blenkernel/BKE_multi_function.h
index 2598a214d5d..403fafeb72e 100644
--- a/source/blender/blenkernel/BKE_multi_function.h
+++ b/source/blender/blenkernel/BKE_multi_function.h
@@ -3,6 +3,7 @@
 
 #include "BKE_generic_array_ref.h"
 #include "BKE_generic_vector_array.h"
+#include "BKE_generic_virtual_list_ref.h"
 #include "BKE_tuple.h"
 
 #include "BLI_vector.h"
@@ -349,12 +350,12 @@ class MFParams {
  public:
   MFParams() = default;
 
-  MFParams(ArrayRef<GenericArrayOrSingleRef> array_or_single_refs,
+  MFParams(ArrayRef<GenericVirtualListRef> virtual_list_refs,
            ArrayRef<GenericMutableArrayRef> mutable_array_refs,
            ArrayRef<GenericVectorArrayOrSingleRef> vector_array_or_single_refs,
            ArrayRef<GenericVectorArray *> vector_arrays,
            const MFSignature &signature)
-      : m_array_or_single_refs(array_or_single_refs),
+      : m_virtual_list_refs(virtual_list_refs),
         m_mutable_array_refs(mutable_array_refs),
         m_vector_array_or_single_refs(vector_array_or_single_refs),
         m_vector_arrays(vector_arrays),
@@ -362,17 +363,17 @@ class MFParams {
   {
   }
 
-  template<typename T> ArrayOrSingleRef<T> readonly_single_input(uint index, StringRef name)
+  template<typename T> VirtualListRef<T> readonly_single_input(uint index, StringRef name)
   {
     BLI_assert(m_signature->is_readonly_single_input<T>(index, name));
     return this->readonly_single_input(index, name).as_typed_ref<T>();
   }
-  GenericArrayOrSingleRef readonly_single_input(uint index, StringRef name)
+  GenericVirtualListRef readonly_single_input(uint index, StringRef name)
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_readonly_single_input(index, name));
     uint corrected_index = m_signature->get_corrected_index(index);
-    return m_array_or_single_refs[corrected_index];
+    return m_virtual_list_refs[corrected_index];
   }
 
   template<typename T> MutableArrayRef<T> single_output(uint index, StringRef name)
@@ -426,7 +427,7 @@ class MFParams {
   }
 
  private:
-  ArrayRef<GenericArrayOrSingleRef> m_array_or_single_refs;
+  ArrayRef<GenericVirtualListRef> m_virtual_list_refs;
   ArrayRef<GenericMutableArrayRef> m_mutable_array_refs;
   ArrayRef<GenericVectorArrayOrSingleRef> m_vector_array_or_single_refs;
   ArrayRef<GenericVectorArray *> m_vector_arrays;
@@ -435,7 +436,7 @@ class MFParams {
 
 class MFParamsBuilder {
  private:
-  Vector<GenericArrayOrSingleRef> m_array_or_single_refs;
+  Vector<GenericVirtualListRef> m_virtual_list_refs;
   Vector<GenericMutableArrayRef> m_mutable_array_refs;
   Vector<GenericVectorArrayOrSingleRef> m_vector_array_or_single_refs;
   Vector<GenericVectorArray *> m_vector_arrays;
@@ -452,7 +453,7 @@ class MFParamsBuilder {
     m_signature = &signature;
     m_min_array_size = min_array_size;
 
-    m_array_or_single_refs.clear();
+    m_virtual_list_refs.clear();
     m_mutable_array_refs.clear();
     m_vector_array_or_single_refs.clear();
     m_vector_arrays.clear();
@@ -461,25 +462,25 @@ class MFParamsBuilder {
   template<typename T> void add_readonly_array_ref(ArrayRef<T> array)
   {
     BLI_assert(array.size() >= m_min_array_size);
-    m_array_or_single_refs.append(GenericArrayOrSingleRef::FromArray<T>(array));
+    m_virtual_list_refs.append(GenericVirtualListRef::FromFullArray<T>(array));
   }
 
   template<typename T> void add_readonly_single_ref(const T *value)
   {
-    m_array_or_single_refs.append(
-        GenericArrayOrSingleRef::FromSingle(GET_TYPE<T>(), (void *)value, m_min_array_size));
+    m_virtual_list_refs.append(
+        GenericVirtualListRef::FromSingle(GET_TYPE<T>(), (void *)value, m_min_array_size));
   }
 
   void add_readonly_array_ref(GenericMutableArrayRef array)
   {
     BLI_assert(array.size() >= m_min_array_size);
-    m_array_or_single_refs.append(
-        GenericArrayOrSingleRef::FromArray(array.type(), array.buffer(), array.size()));
+    m_virtual_list_refs.append(
+        GenericVirtualListRef::FromFu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list