[Bf-blender-cvs] [70fe3d8dea5] functions: extract functions

Jacques Lucke noreply at git.blender.org
Tue Nov 26 17:31:59 CET 2019


Commit: 70fe3d8dea57b7e6550da027546de14ef4e81a6a
Author: Jacques Lucke
Date:   Tue Nov 26 16:52:58 2019 +0100
Branches: functions
https://developer.blender.org/rB70fe3d8dea57b7e6550da027546de14ef4e81a6a

extract functions

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

M	source/blender/blenkernel/BKE_inlined_node_tree.h
M	source/blender/blenkernel/intern/inlined_node_tree.cc

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

diff --git a/source/blender/blenkernel/BKE_inlined_node_tree.h b/source/blender/blenkernel/BKE_inlined_node_tree.h
index 8fe82afb8d6..4ed0d810c2e 100644
--- a/source/blender/blenkernel/BKE_inlined_node_tree.h
+++ b/source/blender/blenkernel/BKE_inlined_node_tree.h
@@ -161,6 +161,10 @@ class InlinedNodeTree : BLI::NonCopyable, BLI::NonMovable {
   XNode &create_node(const VNode &vnode,
                      XParentNode *parent,
                      MutableArrayRef<XSocket *> sockets_map);
+  void remove_expanded_groups_and_interfaces(Vector<XNode *> &all_nodes);
+  void store_tree_in_this_and_init_ids(Vector<XNode *> &&all_nodes,
+                                       Vector<XGroupInput *> &&all_group_inputs,
+                                       Vector<XParentNode *> &&all_parent_nodes);
 };
 
 /* Inline functions
diff --git a/source/blender/blenkernel/intern/inlined_node_tree.cc b/source/blender/blenkernel/intern/inlined_node_tree.cc
index 58751383c09..51513aca064 100644
--- a/source/blender/blenkernel/intern/inlined_node_tree.cc
+++ b/source/blender/blenkernel/intern/inlined_node_tree.cc
@@ -103,36 +103,9 @@ InlinedNodeTree::InlinedNodeTree(bNodeTree *btree, BTreeVTreeMap &vtrees) : m_bt
 
   this->insert_linked_nodes_for_vtree_in_id_order(main_vtree, all_nodes, nullptr);
   this->expand_groups(all_nodes, all_group_inputs, all_parent_nodes, vtrees);
-
-  /* Remove unused nodes. */
-  for (int i = 0; i < all_nodes.size(); i++) {
-    XNode *current_node = all_nodes[i];
-    if (is_group_node(current_node->vnode()) ||
-        (is_interface_node(current_node->vnode()) && current_node->parent() != nullptr)) {
-      all_nodes.remove_and_reorder(i);
-      current_node->destruct_with_sockets();
-      i--;
-    }
-  }
-
-  /* Store used nodes and sockets in 'this'. */
-  m_node_by_id = std::move(all_nodes);
-  m_group_inputs = std::move(all_group_inputs);
-  m_parent_nodes = std::move(all_parent_nodes);
-
-  for (uint node_index : m_node_by_id.index_iterator()) {
-    XNode *xnode = m_node_by_id[node_index];
-    xnode->m_id = node_index;
-
-    for (XInputSocket *xsocket : xnode->m_inputs) {
-      xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket);
-      m_input_sockets.append(xsocket);
-    }
-    for (XOutputSocket *xsocket : xnode->m_outputs) {
-      xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket);
-      m_output_sockets.append(xsocket);
-    }
-  }
+  this->remove_expanded_groups_and_interfaces(all_nodes);
+  this->store_tree_in_this_and_init_ids(
+      std::move(all_nodes), std::move(all_group_inputs), std::move(all_parent_nodes));
 }
 
 BLI_NOINLINE void InlinedNodeTree::expand_groups(Vector<XNode *> &all_nodes,
@@ -271,9 +244,8 @@ void InlinedNodeTree::expand_group_node(XNode &group_node,
   }
 }
 
-void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order(const VirtualNodeTree &vtree,
-                                                                Vector<XNode *> &all_nodes,
-                                                                XParentNode *parent)
+BLI_NOINLINE void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order(
+    const VirtualNodeTree &vtree, Vector<XNode *> &all_nodes, XParentNode *parent)
 {
   BLI::TemporaryArray<XSocket *> sockets_map(vtree.socket_count());
 
@@ -296,9 +268,9 @@ void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order(const VirtualNod
   }
 }
 
-XNode &InlinedNodeTree::create_node(const VNode &vnode,
-                                    XParentNode *parent,
-                                    MutableArrayRef<XSocket *> sockets_map)
+BLI_NOINLINE XNode &InlinedNodeTree::create_node(const VNode &vnode,
+                                                 XParentNode *parent,
+                                                 MutableArrayRef<XSocket *> sockets_map)
 {
   XNode &new_node = *m_allocator.construct<XNode>().release();
   new_node.m_vnode = &vnode;
@@ -330,6 +302,44 @@ XNode &InlinedNodeTree::create_node(const VNode &vnode,
   return new_node;
 }
 
+BLI_NOINLINE void InlinedNodeTree::remove_expanded_groups_and_interfaces(
+    Vector<XNode *> &all_nodes)
+{
+  for (int i = 0; i < all_nodes.size(); i++) {
+    XNode *current_node = all_nodes[i];
+    if (is_group_node(current_node->vnode()) ||
+        (is_interface_node(current_node->vnode()) && current_node->parent() != nullptr)) {
+      all_nodes.remove_and_reorder(i);
+      current_node->destruct_with_sockets();
+      i--;
+    }
+  }
+}
+
+BLI_NOINLINE void InlinedNodeTree::store_tree_in_this_and_init_ids(
+    Vector<XNode *> &&all_nodes,
+    Vector<XGroupInput *> &&all_group_inputs,
+    Vector<XParentNode *> &&all_parent_nodes)
+{
+  m_node_by_id = std::move(all_nodes);
+  m_group_inputs = std::move(all_group_inputs);
+  m_parent_nodes = std::move(all_parent_nodes);
+
+  for (uint node_index : m_node_by_id.index_iterator()) {
+    XNode *xnode = m_node_by_id[node_index];
+    xnode->m_id = node_index;
+
+    for (XInputSocket *xsocket : xnode->m_inputs) {
+      xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket);
+      m_input_sockets.append(xsocket);
+    }
+    for (XOutputSocket *xsocket : xnode->m_outputs) {
+      xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket);
+      m_output_sockets.append(xsocket);
+    }
+  }
+}
+
 static BLI::DotExport::Cluster *get_cluster_for_parent(
     BLI::DotExport::DirectedGraph &graph,
     Map<const XParentNode *, BLI::DotExport::Cluster *> &clusters,



More information about the Bf-blender-cvs mailing list