[Bf-blender-cvs] [ef2b8c1c3af] master: Nodes: Remove unnecessary RNA pointer creation

Hans Goudey noreply at git.blender.org
Mon Apr 18 17:12:46 CEST 2022


Commit: ef2b8c1c3afac9176da936995231523745e21643
Author: Hans Goudey
Date:   Mon Apr 18 10:12:17 2022 -0500
Branches: master
https://developer.blender.org/rBef2b8c1c3afac9176da936995231523745e21643

Nodes: Remove unnecessary RNA pointer creation

`rna_NodeSocket_refine` and `rna_Node_refine` take significant time
when building the `NodeTreeRef` acceleration data structure, but they
aren't used at all. This commit removes their eager calculation and
instead creates them on-demand in the `rna()` functions. They also
aren't inlined to avoid including `RNA_prototypes.h` in the header.

Differential Revision: https://developer.blender.org/D14674

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

M	source/blender/nodes/NOD_node_tree_ref.hh
M	source/blender/nodes/intern/node_tree_ref.cc

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

diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh
index 3ed09de8fab..61d1d11d859 100644
--- a/source/blender/nodes/NOD_node_tree_ref.hh
+++ b/source/blender/nodes/NOD_node_tree_ref.hh
@@ -65,7 +65,6 @@ class SocketRef : NonCopyable, NonMovable {
   bool is_input_;
   int id_;
   int index_;
-  PointerRNA rna_;
   Vector<LinkRef *> directly_linked_links_;
 
   /* These sockets are linked directly, i.e. with a single link in between. */
@@ -101,7 +100,7 @@ class SocketRef : NonCopyable, NonMovable {
   const InputSocketRef &as_input() const;
   const OutputSocketRef &as_output() const;
 
-  PointerRNA *rna() const;
+  PointerRNA rna() const;
 
   StringRefNull idname() const;
   StringRefNull name() const;
@@ -152,7 +151,6 @@ class NodeRef : NonCopyable, NonMovable {
  private:
   NodeTreeRef *tree_;
   bNode *bnode_;
-  PointerRNA rna_;
   int id_;
   Vector<InputSocketRef *> inputs_;
   Vector<OutputSocketRef *> outputs_;
@@ -183,7 +181,7 @@ class NodeRef : NonCopyable, NonMovable {
   bNode *bnode() const;
   bNodeTree *btree() const;
 
-  PointerRNA *rna() const;
+  PointerRNA rna() const;
   StringRefNull idname() const;
   StringRefNull name() const;
   StringRefNull label() const;
@@ -410,11 +408,6 @@ inline const OutputSocketRef &SocketRef::as_output() const
   return static_cast<const OutputSocketRef &>(*this);
 }
 
-inline PointerRNA *SocketRef::rna() const
-{
-  return const_cast<PointerRNA *>(&rna_);
-}
-
 inline StringRefNull SocketRef::idname() const
 {
   return bsocket_->idname;
@@ -571,11 +564,6 @@ inline bNodeTree *NodeRef::btree() const
   return tree_->btree();
 }
 
-inline PointerRNA *NodeRef::rna() const
-{
-  return const_cast<PointerRNA *>(&rna_);
-}
-
 inline StringRefNull NodeRef::idname() const
 {
   return bnode_->idname;
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
index 01a31ab852d..64a8690a869 100644
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ b/source/blender/nodes/intern/node_tree_ref.cc
@@ -21,7 +21,6 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
     node.tree_ = this;
     node.bnode_ = bnode;
     node.id_ = nodes_by_id_.append_and_get_index(&node);
-    RNA_pointer_create(&btree->id, &RNA_Node, bnode, &node.rna_);
 
     LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->inputs) {
       InputSocketRef &socket = *allocator_.construct<InputSocketRef>().release();
@@ -30,7 +29,6 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
       socket.is_input_ = true;
       socket.bsocket_ = bsocket;
       socket.id_ = sockets_by_id_.append_and_get_index(&socket);
-      RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.rna_);
     }
 
     LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->outputs) {
@@ -40,7 +38,6 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
       socket.is_input_ = false;
       socket.bsocket_ = bsocket;
       socket.id_ = sockets_by_id_.append_and_get_index(&socket);
-      RNA_pointer_create(&btree->id, &RNA_NodeSocket, bsocket, &socket.rna_);
     }
 
     LISTBASE_FOREACH (bNodeLink *, blink, &bnode->internal_links) {
@@ -664,4 +661,18 @@ const NodeTreeRef &get_tree_ref_from_map(NodeTreeRefMap &node_tree_refs, bNodeTr
                                           [&]() { return std::make_unique<NodeTreeRef>(&btree); });
 }
 
+PointerRNA NodeRef::rna() const
+{
+  PointerRNA rna;
+  RNA_pointer_create(&tree_->btree()->id, &RNA_Node, bnode_, &rna);
+  return rna;
+}
+
+PointerRNA SocketRef::rna() const
+{
+  PointerRNA rna;
+  RNA_pointer_create(&this->tree().btree()->id, &RNA_NodeSocket, bsocket_, &rna);
+  return rna;
+}
+
 }  // namespace blender::nodes



More information about the Bf-blender-cvs mailing list