[Bf-blender-cvs] [def527c9b03] functions: Do not use a reference counter for Types

Jacques Lucke noreply at git.blender.org
Wed Aug 14 15:34:46 CEST 2019


Commit: def527c9b03aa0b6f035fa0065a32adb6bd4e044
Author: Jacques Lucke
Date:   Wed Aug 14 13:59:05 2019 +0200
Branches: functions
https://developer.blender.org/rBdef527c9b03aa0b6f035fa0065a32adb6bd4e044

Do not use a reference counter for Types

Types can be expected to stay alive until Blender exists.
This also works well with the fact that they are identified
by their pointer.

Furthermore, the number of types is fairly low, but they
are passed around a lot. Maintaining a thread-safe reference
count seems to be unnecessary overhead.

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

M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/functions/backends/cpp/list.hpp
M	source/blender/functions/backends/cpp/tuple.cpp
M	source/blender/functions/backends/cpp/tuple.hpp
M	source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
M	source/blender/functions/backends/llvm/llvm_type_info.hpp
M	source/blender/functions/core/core-c.cpp
M	source/blender/functions/core/core-c.h
M	source/blender/functions/core/data_graph.hpp
M	source/blender/functions/core/data_graph_builder.hpp
M	source/blender/functions/core/function.cpp
M	source/blender/functions/core/function.hpp
M	source/blender/functions/core/function_builder.cpp
M	source/blender/functions/core/function_builder.hpp
M	source/blender/functions/core/type.hpp
M	source/blender/functions/frontends/data_flow_nodes/mappings.cpp
M	source/blender/functions/frontends/data_flow_nodes/mappings.hpp
M	source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp
M	source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
M	source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
M	source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp
M	source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.hpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp
M	source/blender/functions/functions/array_execution.cpp
M	source/blender/functions/functions/auto_vectorization.cpp
M	source/blender/functions/functions/lists.cpp
M	source/blender/functions/functions/lists.hpp
M	source/blender/functions/functions/simple_conversions.cpp
M	source/blender/functions/functions/switch.cpp
M	source/blender/functions/functions/switch.hpp
M	source/blender/functions/types/boolean.cpp
M	source/blender/functions/types/boolean.hpp
M	source/blender/functions/types/external.cpp
M	source/blender/functions/types/external.hpp
M	source/blender/functions/types/lists.cpp
M	source/blender/functions/types/lists.hpp
M	source/blender/functions/types/numeric.cpp
M	source/blender/functions/types/numeric.hpp
M	source/blender/functions/types/types-c.cpp
M	source/blender/functions/types/types-c.h
M	source/blender/modifiers/intern/MOD_functiondeform.c
M	source/blender/modifiers/intern/MOD_functionpoints.c
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/inserters.cpp
M	source/blender/simulations/bparticles/particle_function.hpp
M	source/blender/simulations/bparticles/particle_function_builder.cpp

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

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 8b43fafc1f1..39265277b62 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1770,8 +1770,8 @@ static float dvar_eval_function(ChannelDriver *UNUSED(driver), DriverVar *dvar)
 struct bNodeTree;
 void *get_driver_variable_function(DriverVar *dvar)
 {
-  FnType float_ty = FN_type_borrow_float();
-  FnType int32_ty = FN_type_borrow_int32();
+  FnType float_ty = FN_type_get_float();
+  FnType int32_ty = FN_type_get_int32();
   FnType inputs[] = {int32_ty, NULL};
   FnType outputs[] = {float_ty, NULL};
 
diff --git a/source/blender/functions/backends/cpp/list.hpp b/source/blender/functions/backends/cpp/list.hpp
index 357cc35164b..a38662b5a58 100644
--- a/source/blender/functions/backends/cpp/list.hpp
+++ b/source/blender/functions/backends/cpp/list.hpp
@@ -10,7 +10,7 @@ using SharedList = AutoRefCount<List>;
 
 class List : public RefCounter {
  private:
-  SharedType m_type;
+  Type *m_type;
   CPPTypeInfo *m_type_info;
   void *m_storage;
   uint m_size;
@@ -18,7 +18,7 @@ class List : public RefCounter {
 
  public:
   List() = delete;
-  List(SharedType type) : m_type(std::move(type))
+  List(Type *type) : m_type(std::move(type))
   {
     m_type_info = &m_type->extension<CPPTypeInfo>();
     m_storage = nullptr;
@@ -120,7 +120,7 @@ class List : public RefCounter {
     return m_size;
   }
 
-  SharedType &type()
+  Type *type()
   {
     return m_type;
   }
diff --git a/source/blender/functions/backends/cpp/tuple.cpp b/source/blender/functions/backends/cpp/tuple.cpp
index 5ee43517748..f1dfbf92399 100644
--- a/source/blender/functions/backends/cpp/tuple.cpp
+++ b/source/blender/functions/backends/cpp/tuple.cpp
@@ -2,11 +2,11 @@
 
 namespace FN {
 
-TupleMeta::TupleMeta(ArrayRef<SharedType> types) : m_types(types)
+TupleMeta::TupleMeta(ArrayRef<Type *> types) : m_types(types)
 {
   m_all_trivially_destructible = true;
   m_size__data = 0;
-  for (const SharedType &type : types) {
+  for (const Type *type : types) {
     CPPTypeInfo &info = type->extension<CPPTypeInfo>();
     uint size = info.size();
     uint alignment = info.alignment();
diff --git a/source/blender/functions/backends/cpp/tuple.hpp b/source/blender/functions/backends/cpp/tuple.hpp
index edec4c86e65..79bda3c92e4 100644
--- a/source/blender/functions/backends/cpp/tuple.hpp
+++ b/source/blender/functions/backends/cpp/tuple.hpp
@@ -37,7 +37,7 @@ namespace FN {
 
 class TupleMeta : public RefCounter {
  private:
-  Vector<SharedType> m_types;
+  Vector<Type *> m_types;
   Vector<CPPTypeInfo *> m_type_info;
   Vector<uint> m_offsets;
   Vector<uint> m_sizes;
@@ -46,12 +46,12 @@ class TupleMeta : public RefCounter {
   bool m_all_trivially_destructible;
 
  public:
-  TupleMeta(ArrayRef<SharedType> types = {});
+  TupleMeta(ArrayRef<Type *> types = {});
 
   /**
    * Get an array containing the types of tuples using the meta object.
    */
-  ArrayRef<SharedType> types() const
+  ArrayRef<Type *> types() const
   {
     return m_types;
   }
diff --git a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
index f286246ef5d..6229c30c0e2 100644
--- a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
+++ b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
@@ -106,7 +106,7 @@ class BuildGraphIR : public LLVMBuildIRBody {
                       Map<DataSocket, llvm::Value *> &values) const
   {
     llvm::Value *value_to_forward = values.lookup(output);
-    SharedType &type = m_graph->type_of_socket(output);
+    Type *type = m_graph->type_of_socket(output);
     LLVMTypeInfo &type_info = type->extension<LLVMTypeInfo>();
 
     Vector<DataSocket> targets;
diff --git a/source/blender/functions/backends/llvm/llvm_type_info.hpp b/source/blender/functions/backends/llvm/llvm_type_info.hpp
index 4ebbd1700b4..0c9533a6266 100644
--- a/source/blender/functions/backends/llvm/llvm_type_info.hpp
+++ b/source/blender/functions/backends/llvm/llvm_type_info.hpp
@@ -139,7 +139,7 @@ class PointerLLVMTypeInfo : public LLVMTypeInfo {
   llvm::Value *build_load_ir__relocate(CodeBuilder &builder, llvm::Value *address) const override;
 };
 
-inline llvm::Type *get_llvm_type(SharedType &type, llvm::LLVMContext &context)
+inline llvm::Type *get_llvm_type(Type *type, llvm::LLVMContext &context)
 {
   return type->extension<LLVMTypeInfo>().get_type(context);
 }
diff --git a/source/blender/functions/core/core-c.cpp b/source/blender/functions/core/core-c.cpp
index ad571d57a04..3b529f4b6d5 100644
--- a/source/blender/functions/core/core-c.cpp
+++ b/source/blender/functions/core/core-c.cpp
@@ -44,14 +44,14 @@ uint FN_output_amount(FnFunction fn_c)
 
 bool FN_input_has_type(FnFunction fn_c, uint index, FnType type_c)
 {
-  Type *type1 = unwrap(fn_c)->input_type(index).ptr();
+  Type *type1 = unwrap(fn_c)->input_type(index);
   Type *type2 = unwrap(type_c);
   return type1 == type2;
 }
 
 bool FN_output_has_type(FnFunction fn_c, uint index, FnType type_c)
 {
-  Type *type1 = unwrap(fn_c)->output_type(index).ptr();
+  Type *type1 = unwrap(fn_c)->output_type(index);
   Type *type2 = unwrap(type_c);
   return type1 == type2;
 }
@@ -66,8 +66,3 @@ const char *FN_type_name(FnType type)
 {
   return unwrap(type)->name().data();
 }
-
-void FN_type_free(FnType type)
-{
-  unwrap(type)->decref();
-}
diff --git a/source/blender/functions/core/core-c.h b/source/blender/functions/core/core-c.h
index 56f50b22e93..d777b5b4af2 100644
--- a/source/blender/functions/core/core-c.h
+++ b/source/blender/functions/core/core-c.h
@@ -21,7 +21,6 @@ bool FN_output_has_type(FnFunction fn, uint index, FnType type);
 void FN_function_print(FnFunction fn);
 
 const char *FN_type_name(FnType type);
-void FN_type_free(FnType type);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/functions/core/data_graph.hpp b/source/blender/functions/core/data_graph.hpp
index f7b15298d23..33518c89f7f 100644
--- a/source/blender/functions/core/data_graph.hpp
+++ b/source/blender/functions/core/data_graph.hpp
@@ -394,7 +394,7 @@ class DataGraph : public RefCounter {
     }
   }
 
-  SharedType &type_of_socket(DataSocket socket)
+  Type *type_of_socket(DataSocket socket)
   {
     if (socket.is_input()) {
       return this->type_of_input(socket.id());
@@ -414,23 +414,23 @@ class DataGraph : public RefCounter {
     return this->function_of_output(output_id)->output_name(this->index_of_output(output_id));
   }
 
-  SharedType &type_of_input(uint input_id)
+  Type *type_of_input(uint input_id)
   {
     return this->function_of_input(input_id)->input_type(this->index_of_input(input_id));
   }
 
-  SharedType &type_of_output(uint output_id)
+  Type *type_of_output(uint output_id)
   {
     return this->function_of_output(output_id)->output_type(this->index_of_output(output_id));
   }
 
-  SharedType &type_of_input(DataSocket input_socket)
+  Type *type_of_input(DataSocket input_socket)
   {
     BLI_assert(input_socket.is_input());
     return this->type_of_input(input_socket.id());
   }
 
-  SharedType &type_of_output(DataSocket output_socket)
+  Type *type_of_output(DataSocket output_socket)
   {
     BLI_assert(output_socket.is_output());
     return this->type_of_output(output_socket.id());
diff --git a/source/blender/functions/core/data_graph_builder.hpp b/source/blender/functions/core/data_graph_builder.hpp
index 240e75ae090..0daecd36604 100644
--- a/source/blender/functions/core/data_graph_builder.hpp
+++ b/source/blender/functions/core/data_graph_builder.hpp
@@ -45,7 +45,7 @@ class BuilderInputSocket : public BuilderSocket {
   uint input_id();
   BuilderOutputSocket *origin();
   StringRef name();
-  SharedType &type();
+  Type *type();
 };
 
 class BuilderOutputSocket : public BuilderSocket {
@@ -60,7 +60,7 @@ class BuilderOutputSocket : public BuilderSocket {
   uint output_id();
   ArrayRef<BuilderInputSocket *> targets();
   StringRef name();
-  SharedType &type();
+  Type *type();
 };
 
 class BuilderNode {
@@ -207,7 +207,7 @@ inline StringRef BuilderInputSocket::name()
   return m_node->function()->input_name(this->index());
 }
 
-inline SharedType &BuilderInputSocket::type()
+inline Type *BuilderInputSocket::type()
 {
   return m_node->function()->input_type(this->index());
 }
@@ -227,7 +227,7 @@ inline StringRef BuilderOutputSocket::name()
   return m_node->function()->output_name(this->index());
 }
 
-inline SharedType &BuilderOutputSocket::type()
+inline Type *BuilderOutputSocket::type()
 {
   return m_node->function()->output_type(this->index());
 }
diff --git a/source/blender/functions/core/function.cpp b/source/blender/functions/core/function.cpp
index 14c40b01829..d7164220693 100644
--- a/source/blender/functions/core/function.cpp
+++ b/source/blender/functions/core/function.cpp
@@ -7,9 +7,9 @@ namespace FN {
 
 Function::Function(ChainedStringRef name,
                    ArrayRef<ChainedStringRef> input_names,
-                   ArrayRef<SharedType> input_types,
+                   ArrayRef<Type *> input_types,
                    ArrayRef<ChainedStringRef> output_names,
-                   ArrayRef<SharedType> output_types,
+                   ArrayRef<Type *> output_types,
                    const char *strings)
     : m_name(name),
       m_input_names(input_names),
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index ce508a1ca2c..942017fa390 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -59,9 +59,9 @@ class Function final : public RefCounter {
    */
   Function(ChainedStringRef name,
            ArrayRef<ChainedStringRef> input_names,
-           ArrayRef<SharedType> input_types,
+           ArrayRef<Type *> input_types,
            ArrayRef<ChainedStringRef> output_names,
-           ArrayRef<SharedType> output_types,
+           ArrayRef<Type *> output_types,
            const char *strings);
 
   ~Function();
@@ -102,12 +102,12 @@ class Function final : public RefCounter {
   /**
    * Get the type of the input at the given index.
    */
-  SharedType &input_t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list