Commit: e417f07ee2d1b999a61101fc32e4d1b4b2f109a8
Author: Jacques Lucke
Date:   Tue Feb 19 17:17:38 2019 +0100
Branches: functions
https://developer.blender.org/rBe417f07ee2d1b999a61101fc32e4d1b4b2f109a8

use mempool to allocate nodes

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

M       source/blender/functions/core/data_flow_graph.cpp
M       source/blender/functions/core/data_flow_graph.hpp

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

diff --git a/source/blender/functions/core/data_flow_graph.cpp 
b/source/blender/functions/core/data_flow_graph.cpp
index 99bab5e080a..60d7186e0e0 100644
--- a/source/blender/functions/core/data_flow_graph.cpp
+++ b/source/blender/functions/core/data_flow_graph.cpp
@@ -20,4 +20,38 @@ namespace FN {
                        return 
this->node()->signature().inputs()[m_index].name();
                }
        }
+
+
+       DataFlowGraph::DataFlowGraph()
+       {
+               m_node_pool = new MemPool(sizeof(Node));
+       }
+
+       DataFlowGraph::~DataFlowGraph()
+       {
+               for (const Node *node : m_nodes) {
+                       node->~Node();
+               }
+               delete m_node_pool;
+       }
+
+       const Node *DataFlowGraph::insert(SharedFunction &function)
+       {
+               BLI_assert(this->can_modify());
+
+               void *ptr = m_node_pool->allocate();
+               const Node *node = new(ptr) Node(this, function);
+               m_nodes.add(node);
+               return node;
+       }
+
+       void DataFlowGraph::link(Socket a, Socket b)
+       {
+               BLI_assert(this->can_modify());
+               BLI_assert(a.node() != b.node());
+               BLI_assert(a.is_input() != b.is_input());
+               BLI_assert(a.graph() == this && b.graph() == this);
+
+               m_links.insert(Link::New(a, b));
+       }
 };
\ No newline at end of file
diff --git a/source/blender/functions/core/data_flow_graph.hpp 
b/source/blender/functions/core/data_flow_graph.hpp
index a65410b8506..d23a47e1e2b 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -4,6 +4,7 @@
 
 #include "BLI_small_set.hpp"
 #include "BLI_small_set_vector.hpp"
+#include "BLI_mempool.hpp"
 
 namespace FN {
 
@@ -162,32 +163,12 @@ namespace FN {
 
        class DataFlowGraph {
        public:
-               DataFlowGraph() = default;
+               DataFlowGraph();
 
-               ~DataFlowGraph()
-               {
-                       for (const Node *node : m_nodes) {
-                               delete node;
-                       }
-               }
-
-               const Node *insert(SharedFunction &function)
-               {
-                       BLI_assert(this->can_modify());
-                       const Node *node = new Node(this, function);
-                       m_nodes.add(node);
-                       return node;
-               }
+               ~DataFlowGraph();
 
-               void link(Socket a, Socket b)
-               {
-                       BLI_assert(this->can_modify());
-                       BLI_assert(a.node() != b.node());
-                       BLI_assert(a.is_input() != b.is_input());
-                       BLI_assert(a.graph() == this && b.graph() == this);
-
-                       m_links.insert(Link::New(a, b));
-               }
+               const Node *insert(SharedFunction &function);
+               void link(Socket a, Socket b);
 
                inline bool can_modify() const
                {
@@ -220,6 +201,7 @@ namespace FN {
                bool m_frozen = false;
                SmallSet<const Node *> m_nodes;
                GraphLinks m_links;
+               MemPool *m_node_pool;
 
                friend Node;
                friend Socket;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to