diff options
author | Jacques Lucke <jacques@blender.org> | 2020-06-30 14:35:38 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-06-30 14:35:45 +0300 |
commit | 84901f2edaf1b00e242ca5d5c24c452ca9c5b922 (patch) | |
tree | eb48ecaf2140d4b8e86f6c2d4166e698b8d8063b /source | |
parent | a6775efb4f26531c299b805915f5865b06fad75b (diff) |
Nodes: store nodes by bNodeType instead of idname
This is more efficient in most cases.
Diffstat (limited to 'source')
4 files changed, 28 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_derived_node_tree.hh b/source/blender/blenkernel/BKE_derived_node_tree.hh index a9a94e75d9f..1c586f9b4c6 100644 --- a/source/blender/blenkernel/BKE_derived_node_tree.hh +++ b/source/blender/blenkernel/BKE_derived_node_tree.hh @@ -173,14 +173,15 @@ class DerivedNodeTree : NonCopyable, NonMovable { Vector<DInputSocket *> m_input_sockets; Vector<DOutputSocket *> m_output_sockets; - Map<std::string, Vector<DNode *>> m_nodes_by_idname; + Map<const bNodeType *, Vector<DNode *>> m_nodes_by_type; public: DerivedNodeTree(bNodeTree *btree, NodeTreeRefMap &node_tree_refs); ~DerivedNodeTree(); Span<const DNode *> nodes() const; - Span<const DNode *> nodes_with_idname(StringRef idname) const; + Span<const DNode *> nodes_by_type(StringRefNull idname) const; + Span<const DNode *> nodes_by_type(const bNodeType *nodetype) const; Span<const DSocket *> sockets() const; Span<const DInputSocket *> input_sockets() const; @@ -428,9 +429,15 @@ inline Span<const DNode *> DerivedNodeTree::nodes() const return m_nodes_by_id.as_span(); } -inline Span<const DNode *> DerivedNodeTree::nodes_with_idname(StringRef idname) const +inline Span<const DNode *> DerivedNodeTree::nodes_by_type(StringRefNull idname) const { - const Vector<DNode *> *nodes = m_nodes_by_idname.lookup_ptr(idname); + const bNodeType *nodetype = nodeTypeFind(idname.data()); + return this->nodes_by_type(nodetype); +} + +inline Span<const DNode *> DerivedNodeTree::nodes_by_type(const bNodeType *nodetype) const +{ + const Vector<DNode *> *nodes = m_nodes_by_type.lookup_ptr(nodetype); if (nodes == nullptr) { return {}; } diff --git a/source/blender/blenkernel/BKE_node_tree_ref.hh b/source/blender/blenkernel/BKE_node_tree_ref.hh index 718a93b0089..557eb44e5df 100644 --- a/source/blender/blenkernel/BKE_node_tree_ref.hh +++ b/source/blender/blenkernel/BKE_node_tree_ref.hh @@ -163,14 +163,15 @@ class NodeTreeRef : NonCopyable, NonMovable { Vector<SocketRef *> m_sockets_by_id; Vector<InputSocketRef *> m_input_sockets; Vector<OutputSocketRef *> m_output_sockets; - Map<std::string, Vector<NodeRef *>> m_nodes_by_idname; + Map<const bNodeType *, Vector<NodeRef *>> m_nodes_by_type; public: NodeTreeRef(bNodeTree *btree); ~NodeTreeRef(); Span<const NodeRef *> nodes() const; - Span<const NodeRef *> nodes_with_idname(StringRef idname) const; + Span<const NodeRef *> nodes_by_type(StringRefNull idname) const; + Span<const NodeRef *> nodes_by_type(const bNodeType *nodetype) const; Span<const SocketRef *> sockets() const; Span<const InputSocketRef *> input_sockets() const; @@ -403,9 +404,15 @@ inline Span<const NodeRef *> NodeTreeRef::nodes() const return m_nodes_by_id.as_span(); } -inline Span<const NodeRef *> NodeTreeRef::nodes_with_idname(StringRef idname) const +inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) const { - const Vector<NodeRef *> *nodes = m_nodes_by_idname.lookup_ptr(idname); + const bNodeType *nodetype = nodeTypeFind(idname.data()); + return this->nodes_by_type(nodetype); +} + +inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(const bNodeType *nodetype) const +{ + const Vector<NodeRef *> *nodes = m_nodes_by_type.lookup_ptr(nodetype); if (nodes == nullptr) { return {}; } diff --git a/source/blender/blenkernel/intern/derived_node_tree.cc b/source/blender/blenkernel/intern/derived_node_tree.cc index d6e1a127048..b53457812ba 100644 --- a/source/blender/blenkernel/intern/derived_node_tree.cc +++ b/source/blender/blenkernel/intern/derived_node_tree.cc @@ -174,7 +174,7 @@ BLI_NOINLINE void DerivedNodeTree::relink_group_inputs(const NodeTreeRef &group_ Span<DNode *> nodes_by_id, DNode &group_node) { - Span<const NodeRef *> node_refs = group_ref.nodes_with_idname("NodeGroupInput"); + Span<const NodeRef *> node_refs = group_ref.nodes_by_type("NodeGroupInput"); if (node_refs.size() == 0) { return; } @@ -221,7 +221,7 @@ BLI_NOINLINE void DerivedNodeTree::relink_group_outputs(const NodeTreeRef &group Span<DNode *> nodes_by_id, DNode &group_node) { - Span<const NodeRef *> node_refs = group_ref.nodes_with_idname("NodeGroupOutput"); + Span<const NodeRef *> node_refs = group_ref.nodes_by_type("NodeGroupOutput"); if (node_refs.size() == 0) { return; } @@ -321,7 +321,8 @@ BLI_NOINLINE void DerivedNodeTree::store_in_this_and_init_ids( DNode *node = m_nodes_by_id[node_index]; node->m_id = node_index; - m_nodes_by_idname.lookup_or_add_default(node->idname()).append(node); + const bNodeType *nodetype = node->m_node_ref->bnode()->typeinfo; + m_nodes_by_type.lookup_or_add_default(nodetype).append(node); for (DInputSocket *socket : node->m_inputs) { socket->m_id = m_sockets_by_id.append_and_get_index(socket); diff --git a/source/blender/blenkernel/intern/node_tree_ref.cc b/source/blender/blenkernel/intern/node_tree_ref.cc index 54680293ccc..6bd3e2d2e5a 100644 --- a/source/blender/blenkernel/intern/node_tree_ref.cc +++ b/source/blender/blenkernel/intern/node_tree_ref.cc @@ -79,7 +79,8 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : m_btree(btree) } for (NodeRef *node : m_nodes_by_id) { - m_nodes_by_idname.lookup_or_add_default(node->idname()).append(node); + const bNodeType *nodetype = node->m_bnode->typeinfo; + m_nodes_by_type.lookup_or_add_default(nodetype).append(node); } } |