[Bf-blender-cvs] [1fd26737b52] functions: use virtual socket index to replace a map with a vector

Jacques Lucke noreply at git.blender.org
Thu Aug 1 18:22:56 CEST 2019


Commit: 1fd26737b527aa3108c1f715eadce9c5c8bbd336
Author: Jacques Lucke
Date:   Thu Aug 1 10:16:56 2019 +0200
Branches: functions
https://developer.blender.org/rB1fd26737b527aa3108c1f715eadce9c5c8bbd336

use virtual socket index to replace a map with a vector

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

M	source/blender/functions/core/data_flow_graph.hpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp

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

diff --git a/source/blender/functions/core/data_flow_graph.hpp b/source/blender/functions/core/data_flow_graph.hpp
index 769e1cd2ff2..8cc713b8d93 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -42,6 +42,16 @@ struct DFGraphSocket {
   {
   }
 
+  static DFGraphSocket None()
+  {
+    return DFGraphSocket(false, (uint)-1);
+  }
+
+  bool is_none() const
+  {
+    return m_id == (uint)-1;
+  }
+
   static DFGraphSocket FromInput(uint id)
   {
     return DFGraphSocket(false, id);
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
index 3e335f19d2e..79b4b378366 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
@@ -15,10 +15,10 @@ using BLI::ValueOrError;
 class VTreeDataGraph {
  private:
   SharedDataFlowGraph m_graph;
-  Map<VirtualSocket *, DFGraphSocket> m_socket_map;
+  Vector<DFGraphSocket> m_socket_map;
 
  public:
-  VTreeDataGraph(SharedDataFlowGraph graph, Map<VirtualSocket *, DFGraphSocket> mapping)
+  VTreeDataGraph(SharedDataFlowGraph graph, Vector<DFGraphSocket> mapping)
       : m_graph(std::move(graph)), m_socket_map(std::move(mapping))
   {
   }
@@ -30,17 +30,21 @@ class VTreeDataGraph {
 
   DFGraphSocket *lookup_socket_ptr(VirtualSocket *vsocket)
   {
-    return m_socket_map.lookup_ptr(vsocket);
+    DFGraphSocket *socket = &m_socket_map[vsocket->id()];
+    if (socket->is_none()) {
+      return nullptr;
+    }
+    return socket;
   }
 
   DFGraphSocket lookup_socket(VirtualSocket *vsocket)
   {
-    return m_socket_map.lookup(vsocket);
+    return m_socket_map[vsocket->id()];
   }
 
   bool uses_socket(VirtualSocket *vsocket)
   {
-    return m_socket_map.contains(vsocket);
+    return !m_socket_map[vsocket->id()].is_none();
   }
 
   struct PlaceholderDependencies {
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
index 2222172da8b..e31a89779a8 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
@@ -35,15 +35,16 @@ VTreeDataGraphBuilder::VTreeDataGraphBuilder(VirtualNodeTree &vtree)
 {
 }
 
-static Map<VirtualSocket *, DFGraphSocket> build_mapping_for_original_sockets(
+static Vector<DFGraphSocket> build_mapping_for_original_sockets(
+    VirtualNodeTree &vtree,
     Map<VirtualSocket *, DFGB_Socket> &socket_map,
     DataFlowGraph::ToBuilderMapping &builder_mapping)
 {
-  Map<VirtualSocket *, DFGraphSocket> original_socket_mapping;
+  Vector<DFGraphSocket> original_socket_mapping(vtree.socket_count(), DFGraphSocket::None());
   for (auto item : socket_map.items()) {
     VirtualSocket *vsocket = item.key;
     DFGraphSocket socket = builder_mapping.map_socket(item.value);
-    original_socket_mapping.add_new(vsocket, socket);
+    original_socket_mapping[vsocket->id()] = socket;
   }
   return original_socket_mapping;
 }
@@ -52,8 +53,9 @@ VTreeDataGraph VTreeDataGraphBuilder::build()
 {
   m_graph_builder.to_dot__clipboard();
   auto build_result = DataFlowGraph::FromBuilder(m_graph_builder);
-  return VTreeDataGraph(std::move(build_result.graph),
-                        build_mapping_for_original_sockets(m_socket_map, build_result.mapping));
+  return VTreeDataGraph(
+      std::move(build_result.graph),
+      build_mapping_for_original_sockets(m_vtree, m_socket_map, build_result.mapping));
 }
 
 class NodeSource : public SourceInfo {



More information about the Bf-blender-cvs mailing list