[Bf-blender-cvs] [a911775cbe1] functions: store attributes info directly instead of unique pointer

Jacques Lucke noreply at git.blender.org
Tue Sep 10 14:24:11 CEST 2019


Commit: a911775cbe15f696a91c0fcc5c05159d7ec7827f
Author: Jacques Lucke
Date:   Tue Sep 10 13:02:12 2019 +0200
Branches: functions
https://developer.blender.org/rBa911775cbe15f696a91c0fcc5c05159d7ec7827f

store attributes info directly instead of unique pointer

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

M	source/blender/blenkernel/BKE_attributes_block_container.hpp
M	source/blender/blenkernel/intern/attributes_block_container.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/blenkernel/BKE_attributes_block_container.hpp b/source/blender/blenkernel/BKE_attributes_block_container.hpp
index 9bd886d688a..a92f7c1881d 100644
--- a/source/blender/blenkernel/BKE_attributes_block_container.hpp
+++ b/source/blender/blenkernel/BKE_attributes_block_container.hpp
@@ -13,24 +13,24 @@ class AttributesBlock;
 
 class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
  private:
-  std::unique_ptr<AttributesInfo> m_attributes_info;
+  AttributesInfo m_attributes_info;
   uint m_block_size;
   SetVector<AttributesBlock *> m_active_blocks;
   std::mutex m_blocks_mutex;
   std::atomic<uint> m_next_id;
 
  public:
-  AttributesBlockContainer(std::unique_ptr<AttributesInfo> attributes_info, uint block_size);
+  AttributesBlockContainer(AttributesInfo attributes_info, uint block_size);
   ~AttributesBlockContainer();
 
   uint count_active() const;
 
   const AttributesInfo &attributes_info() const
   {
-    return *m_attributes_info;
+    return m_attributes_info;
   }
 
-  void update_attributes(std::unique_ptr<AttributesInfo> new_info);
+  void update_attributes(AttributesInfo new_info);
 
   AttributesBlock *new_block();
   void release_block(AttributesBlock *block);
@@ -39,7 +39,7 @@ class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
 
   template<typename T> Vector<T> flatten_attribute(StringRef attribute_name)
   {
-    BLI_assert(m_attributes_info->type_of(attribute_name) == attribute_type_by_type<T>::value);
+    BLI_assert(m_attributes_info.type_of(attribute_name) == attribute_type_by_type<T>::value);
     Vector<T> result(this->count_active());
     this->flatten_attribute(attribute_name, (void *)result.begin());
     return result;
diff --git a/source/blender/blenkernel/intern/attributes_block_container.cpp b/source/blender/blenkernel/intern/attributes_block_container.cpp
index 1f9ca5045fe..64ed2613cf0 100644
--- a/source/blender/blenkernel/intern/attributes_block_container.cpp
+++ b/source/blender/blenkernel/intern/attributes_block_container.cpp
@@ -2,11 +2,9 @@
 
 namespace BKE {
 
-AttributesBlockContainer::AttributesBlockContainer(std::unique_ptr<AttributesInfo> attributes_info,
-                                                   uint block_size)
+AttributesBlockContainer::AttributesBlockContainer(AttributesInfo attributes_info, uint block_size)
     : m_attributes_info(std::move(attributes_info)), m_block_size(block_size)
 {
-  BLI_assert(m_attributes_info.get() != nullptr);
 }
 
 AttributesBlockContainer::~AttributesBlockContainer()
@@ -25,9 +23,9 @@ uint AttributesBlockContainer::count_active() const
   return amount;
 }
 
-void AttributesBlockContainer::update_attributes(std::unique_ptr<AttributesInfo> new_info)
+void AttributesBlockContainer::update_attributes(AttributesInfo new_info)
 {
-  AttributesInfoDiff info_diff(*m_attributes_info, *new_info);
+  AttributesInfoDiff info_diff(m_attributes_info, new_info);
   for (auto &block : m_active_blocks) {
     block->update_buffers(info_diff);
   }
@@ -57,8 +55,8 @@ void AttributesBlockContainer::release_block(AttributesBlock *block)
 
 void AttributesBlockContainer::flatten_attribute(StringRef attribute_name, void *dst) const
 {
-  uint attribute_index = m_attributes_info->attribute_index(attribute_name);
-  uint element_size = size_of_attribute_type(m_attributes_info->type_of(attribute_index));
+  uint attribute_index = m_attributes_info.attribute_index(attribute_name);
+  uint element_size = size_of_attribute_type(m_attributes_info.type_of(attribute_index));
 
   uint offset = 0;
   for (AttributesBlock *block : m_active_blocks) {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 9588fb2423f..cda28f1bbc2 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -508,8 +508,7 @@ BLI_NOINLINE static void ensure_required_containers_exist(
 
   types_to_simulate.foreach_key([&containers](StringRefNull type_name) {
     if (!containers.contains(type_name)) {
-      AttributesBlockContainer *container = new AttributesBlockContainer(
-          std::unique_ptr<AttributesInfo>(new AttributesInfo()), 1000);
+      AttributesBlockContainer *container = new AttributesBlockContainer(AttributesInfo(), 1000);
       containers.add_new(type_name, container);
     }
   });
@@ -544,8 +543,7 @@ BLI_NOINLINE static void ensure_required_attributes_exist(
 
         AttributesInfo new_attributes_info = build_attribute_info_for_type(
             type_info, container.attributes_info());
-        container.update_attributes(
-            std::unique_ptr<AttributesInfo>(new AttributesInfo(std::move(new_attributes_info))));
+        container.update_attributes(new_attributes_info);
       });
 }



More information about the Bf-blender-cvs mailing list