[Bf-blender-cvs] [ce14c2c7bd4] functions: store default value per CPPType

Jacques Lucke noreply at git.blender.org
Thu Feb 6 16:44:44 CET 2020


Commit: ce14c2c7bd46d8460445bb20d19491b1d1941900
Author: Jacques Lucke
Date:   Thu Feb 6 16:44:32 2020 +0100
Branches: functions
https://developer.blender.org/rBce14c2c7bd46d8460445bb20d19491b1d1941900

store default value per CPPType

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

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

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

diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index cf4a1773f12..3ad29896cc4 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -46,9 +46,8 @@ class AttributesInfoBuilder : BLI::NonCopyable, BLI::NonMovable {
     if (m_names.add(name)) {
       m_types.append(&type);
       void *dst = m_allocator.allocate(type.size(), type.alignment());
-      memset(dst, 0, type.size());
       if (default_value == nullptr) {
-        type.construct_default(dst);
+        type.copy_to_uninitialized(type.default_value(), dst);
       }
       else {
         type.copy_to_uninitialized(default_value, dst);
diff --git a/source/blender/functions/FN_cpp_type.h b/source/blender/functions/FN_cpp_type.h
index fcc2880c3fc..49d5f389b6a 100644
--- a/source/blender/functions/FN_cpp_type.h
+++ b/source/blender/functions/FN_cpp_type.h
@@ -71,7 +71,8 @@ class CPPType {
           FillInitializedIndicesF fill_initialized_indices,
           FillUninitializedF fill_uninitialized,
           FillUninitializedIndicesF fill_uninitialized_indices,
-          uint32_t type_hash)
+          uint32_t type_hash,
+          const void *default_value)
       : m_size(size),
         m_alignment(alignment),
         m_trivially_destructible(trivially_destructible),
@@ -98,6 +99,7 @@ class CPPType {
         m_fill_uninitialized(fill_uninitialized),
         m_fill_uninitialized_indices(fill_uninitialized_indices),
         m_type_hash(type_hash),
+        m_default_value(default_value),
         m_name(name)
   {
     BLI_assert(is_power_of_2_i(m_alignment));
@@ -305,6 +307,11 @@ class CPPType {
     m_fill_uninitialized_indices(value, dst, index_mask);
   }
 
+  const void *default_value() const
+  {
+    return m_default_value;
+  }
+
   uint32_t type_hash() const
   {
     return m_type_hash;
@@ -357,6 +364,7 @@ class CPPType {
   FillUninitializedIndicesF m_fill_uninitialized_indices;
 
   uint32_t m_type_hash;
+  const void *m_default_value;
   std::string m_name;
 };
 
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index cd523cfec9f..22d23e7961c 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -160,7 +160,9 @@ void FillUninitializedIndices_CB(const void *value, void *dst, IndexMask index_m
 }
 
 template<typename T>
-static std::unique_ptr<const CPPType> create_cpp_type(StringRef name, uint32_t type_hash)
+static std::unique_ptr<const CPPType> create_cpp_type(StringRef name,
+                                                      uint32_t type_hash,
+                                                      const T &default_value)
 {
   const CPPType *type = new CPPType(name,
                                     sizeof(T),
@@ -188,13 +190,15 @@ static std::unique_ptr<const CPPType> create_cpp_type(StringRef name, uint32_t t
                                     FillInitializedIndices_CB<T>,
                                     FillUninitialized_CB<T>,
                                     FillUninitializedIndices_CB<T>,
-                                    type_hash);
+                                    type_hash,
+                                    (const void *)&default_value);
   return std::unique_ptr<const CPPType>(type);
 }
 
 #define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME) \
+  static TYPE_NAME default_value_##IDENTIFIER; \
   static std::unique_ptr<const CPPType> CPPTYPE_##IDENTIFIER = create_cpp_type<TYPE_NAME>( \
-      STRINGIFY(IDENTIFIER), BLI_RAND_PER_LINE_UINT32); \
+      STRINGIFY(IDENTIFIER), BLI_RAND_PER_LINE_UINT32, default_value_##IDENTIFIER); \
   template<> const CPPType &CPP_TYPE<TYPE_NAME>() \
   { \
     return *CPPTYPE_##IDENTIFIER; \



More information about the Bf-blender-cvs mailing list