[Bf-blender-cvs] [85c43fbd2ed] functions: store a random hash per type

Jacques Lucke noreply at git.blender.org
Sun Jan 19 12:46:05 CET 2020


Commit: 85c43fbd2edfcaa751e00d663f8633c522f2b406
Author: Jacques Lucke
Date:   Sun Jan 19 11:47:43 2020 +0100
Branches: functions
https://developer.blender.org/rB85c43fbd2edfcaa751e00d663f8633c522f2b406

store a random hash per type

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

M	source/blender/functions/FN_cpp_type.h
M	source/blender/functions/intern/cpp_types.cc

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

diff --git a/source/blender/functions/FN_cpp_type.h b/source/blender/functions/FN_cpp_type.h
index c6b30d89a5f..fcc2880c3fc 100644
--- a/source/blender/functions/FN_cpp_type.h
+++ b/source/blender/functions/FN_cpp_type.h
@@ -70,7 +70,8 @@ class CPPType {
           FillInitializedF fill_initialized,
           FillInitializedIndicesF fill_initialized_indices,
           FillUninitializedF fill_uninitialized,
-          FillUninitializedIndicesF fill_uninitialized_indices)
+          FillUninitializedIndicesF fill_uninitialized_indices,
+          uint32_t type_hash)
       : m_size(size),
         m_alignment(alignment),
         m_trivially_destructible(trivially_destructible),
@@ -96,6 +97,7 @@ class CPPType {
         m_fill_initialized_indices(fill_initialized_indices),
         m_fill_uninitialized(fill_uninitialized),
         m_fill_uninitialized_indices(fill_uninitialized_indices),
+        m_type_hash(type_hash),
         m_name(name)
   {
     BLI_assert(is_power_of_2_i(m_alignment));
@@ -303,6 +305,11 @@ class CPPType {
     m_fill_uninitialized_indices(value, dst, index_mask);
   }
 
+  uint32_t type_hash() const
+  {
+    return m_type_hash;
+  }
+
   friend bool operator==(const CPPType &a, const CPPType &b)
   {
     return &a == &b;
@@ -349,6 +356,7 @@ class CPPType {
   FillUninitializedF m_fill_uninitialized;
   FillUninitializedIndicesF m_fill_uninitialized_indices;
 
+  uint32_t m_type_hash;
   std::string m_name;
 };
 
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index ba6473b5dda..cd523cfec9f 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -2,6 +2,7 @@
 #include "cpp_types.h"
 
 #include "BLI_math_cxx.h"
+#include "BLI_rand_cxx.h"
 
 #include "BKE_surface_hook.h"
 
@@ -158,7 +159,8 @@ void FillUninitializedIndices_CB(const void *value, void *dst, IndexMask index_m
   index_mask.foreach_index([=](uint i) { new (dst_ + i) T(value_); });
 }
 
-template<typename T> static std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
+template<typename T>
+static std::unique_ptr<const CPPType> create_cpp_type(StringRef name, uint32_t type_hash)
 {
   const CPPType *type = new CPPType(name,
                                     sizeof(T),
@@ -185,13 +187,14 @@ template<typename T> static std::unique_ptr<const CPPType> create_cpp_type(Strin
                                     FillInitialized_CB<T>,
                                     FillInitializedIndices_CB<T>,
                                     FillUninitialized_CB<T>,
-                                    FillUninitializedIndices_CB<T>);
+                                    FillUninitializedIndices_CB<T>,
+                                    type_hash);
   return std::unique_ptr<const CPPType>(type);
 }
 
 #define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME) \
   static std::unique_ptr<const CPPType> CPPTYPE_##IDENTIFIER = create_cpp_type<TYPE_NAME>( \
-      STRINGIFY(IDENTIFIER)); \
+      STRINGIFY(IDENTIFIER), BLI_RAND_PER_LINE_UINT32); \
   template<> const CPPType &CPP_TYPE<TYPE_NAME>() \
   { \
     return *CPPTYPE_##IDENTIFIER; \



More information about the Bf-blender-cvs mailing list