Cleanup: Don't do recursion where possible in node.cc #105394

Merged
Hans Goudey merged 25 commits from mod_moder/blender:cleanup_bke_nodes_unwrap_recursion into main 2023-03-06 18:39:30 +01:00
2 changed files with 42 additions and 50 deletions
Showing only changes of commit 90c1420a0c - Show all commits

View File

@ -503,7 +503,7 @@ struct bNodeTree *ntreeFromID(struct ID *id);
void ntreeFreeLocalNode(struct bNodeTree *ntree, struct bNode *node);
void ntreeFreeLocalTree(struct bNodeTree *ntree);
struct bNode *ntreeFindType(struct bNodeTree *ntree, const int type);
struct bNode *ntreeFindType(struct bNodeTree *ntree, int type);
/**
* Check recursively if a node tree contains another.
@ -553,14 +553,14 @@ void ntreeBlendReadExpand(struct BlendExpander *expander, struct bNodeTree *ntre
* \{ */
struct bNodeSocket *ntreeFindSocketInterface(struct bNodeTree *ntree,
const eNodeSocketInOut in_out,
eNodeSocketInOut in_out,
const char *identifier);
struct bNodeSocket *ntreeAddSocketInterface(struct bNodeTree *ntree,
const eNodeSocketInOut in_out,
eNodeSocketInOut in_out,
const char *idname,
const char *name);
struct bNodeSocket *ntreeInsertSocketInterface(struct bNodeTree *ntree,
const eNodeSocketInOut in_out,
eNodeSocketInOut in_out,
const char *idname,
struct bNodeSocket *next_sock,
const char *name);
@ -612,9 +612,9 @@ struct GHashIterator *nodeSocketTypeGetIterator(void);
const char *nodeSocketTypeLabel(const bNodeSocketType *stype);
bool nodeIsStaticSocketType(const struct bNodeSocketType *stype);
const char *nodeStaticSocketType(const int type, const int subtype);
const char *nodeStaticSocketInterfaceType(const int type, const int subtype);
const char *nodeStaticSocketLabel(const int type, const int subtype);
const char *nodeStaticSocketType(int type, int subtype);
const char *nodeStaticSocketInterfaceType(int type, int subtype);
const char *nodeStaticSocketLabel(int type, int subtype);
/* Helper macros for iterating over node types. */
#define NODE_SOCKET_TYPES_BEGIN(stype) \
@ -632,11 +632,11 @@ const char *nodeStaticSocketLabel(const int type, const int subtype);
((void)0)
struct bNodeSocket *nodeFindSocket(const struct bNode *node,
const eNodeSocketInOut in_out,
eNodeSocketInOut in_out,
const char *identifier);
struct bNodeSocket *nodeAddSocket(struct bNodeTree *ntree,
struct bNode *node,
const eNodeSocketInOut in_out,
eNodeSocketInOut in_out,
const char *idname,
const char *identifier,
const char *name);
@ -651,17 +651,14 @@ void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeS
void nodeRemoveSocketEx(struct bNodeTree *ntree,
struct bNode *node,
struct bNodeSocket *sock,
const bool do_id_user);
bool do_id_user);
void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node);
void nodeModifySocketType(struct bNodeTree *ntree,
struct bNode *node,
struct bNodeSocket *sock,
const char *idname);
void nodeModifySocketTypeStatic(struct bNodeTree *ntree,
struct bNode *node,
struct bNodeSocket *sock,
const int type,
const int subtype);
void nodeModifySocketTypeStatic(
struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, int type, int subtype);
struct bNode *nodeAddNode(const struct bContext *C, struct bNodeTree *ntree, const char *idname);
struct bNode *nodeAddStaticNode(const struct bContext *C, struct bNodeTree *ntree, const int type);
@ -692,7 +689,7 @@ void nodeRebuildIDVector(struct bNodeTree *node_tree);
void nodeRemoveNode(struct Main *bmain,
struct bNodeTree *ntree,
struct bNode *node,
const bool do_id_user);
bool do_id_user);
void nodeDimensionsGet(const struct bNode *node, float *r_width, float *r_height);
void nodeTagUpdateID(struct bNode *node);
@ -745,8 +742,8 @@ bool nodeLinkIsHidden(const struct bNodeLink *link);
bool nodeLinkIsSelected(const struct bNodeLink *link);
void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
void nodeToView(const struct bNode *node, const float x, const float y, float *rx, float *ry);
void nodeFromView(const struct bNode *node, const float x, const float y, float *rx, float *ry);
void nodeToView(const struct bNode *node, float x, float y, float *rx, float *ry);
void nodeFromView(const struct bNode *node, float x, float y, float *rx, float *ry);
bool nodeAttachNodeCheck(const struct bNode *node, const struct bNode *parent);
void nodeAttachNode(struct bNodeTree *ntree, struct bNode *node, struct bNode *parent);
void nodeDetachNode(struct bNodeTree *ntree, struct bNode *node);
@ -813,7 +810,7 @@ void nodeChainIterBackwards(const bNodeTree *ntree,
const bNode *node_start,
bool (*callback)(bNode *, bNode *, void *),
void *userdata,
const int recursion_lvl);
int recursion_lvl);
/**
* Iterate over all parents of \a node, executing \a callback for each parent
* (which can return false to end iterator)
@ -855,7 +852,7 @@ bool nodeSupportsActiveFlag(const struct bNode *node, int sub_active);
void nodeSetSocketAvailability(struct bNodeTree *ntree,
struct bNodeSocket *sock,
const bool is_available);
bool is_available);
int nodeSocketLinkLimit(const struct bNodeSocket *sock);
@ -973,10 +970,7 @@ void BKE_node_preview_merge_tree(struct bNodeTree *to_ntree,
/** \name Node Type Access
* \{ */
void nodeLabel(const struct bNodeTree *ntree,
const struct bNode *node,
char *label,
const int maxlen);
void nodeLabel(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen);
/**
* Get node socket label if it is set.
*/
@ -989,19 +983,16 @@ bool nodeGroupPoll(const struct bNodeTree *nodetree,
/**
* Initialize a new node type struct with default values and callbacks.
*/
void node_type_base(struct bNodeType *ntype, const int type, const char *name, const short nclass);
void node_type_base(struct bNodeType *ntype, int type, const char *name, const short nclass);
void node_type_base_custom(struct bNodeType *ntype,
const char *idname,
const char *name,
const short nclass);
short nclass);
void node_type_socket_templates(struct bNodeType *ntype,
struct bNodeSocketTemplate *inputs,
struct bNodeSocketTemplate *outputs);
void node_type_size(struct bNodeType *ntype,
const int width,
const int minwidth,
const int maxwidth);
void node_type_size_preset(struct bNodeType *ntype, const eNodeSizePreset size);
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth);
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size);
/**
* \warning Nodes defining a storage type _must_ allocate this for new nodes.
* Otherwise nodes will reload as undefined (#46619).
@ -1594,11 +1585,9 @@ extern struct bNodeSocketType NodeSocketTypeUndefined;
namespace blender::bke {
bNodeSocket *node_find_enabled_socket(bNode &node,
const eNodeSocketInOut in_out,
const StringRef name);
bNodeSocket *node_find_enabled_input_socket(bNode &node, const StringRef name);
bNodeSocket *node_find_enabled_output_socket(bNode &node, const StringRef name);
bNodeSocket *node_find_enabled_socket(bNode &node, eNodeSocketInOut in_out, StringRef name);
bNodeSocket *node_find_enabled_input_socket(bNode &node, StringRef name);
bNodeSocket *node_find_enabled_output_socket(bNode &node, StringRef name);
} // namespace blender::bke

View File

@ -2917,22 +2917,25 @@ void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, boo
void nodeUnlinkNode(bNodeTree *ntree, const bNode *node)
{
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
if (!ELEM(node, link->fromnode, link->tonode)) {
continue;
ListBase const *lb = nullptr;
if (link->fromnode == node) {
lb = &node->outputs;
}
else if (link->tonode == node) {
lb = &node->inputs;
}
/* Only bother adjusting if the socket is not on the node we're deleting. */
if (link->tonode != node && link->tosock->flag & SOCK_MULTI_INPUT) {
adjust_multi_input_indices_after_removed_link(
ntree, link->tosock, link->multi_input_socket_index);
}
const bool validate_outputs = node == link->fromnode;
const ListBase *sockets = validate_outputs ? &node->outputs : &node->inputs;
LISTBASE_FOREACH (const bNodeSocket *, sock, sockets) {
if (link->fromsock == sock || link->tosock == sock) {
nodeRemLink(ntree, link);
break;
if (lb) {
/* Only bother adjusting if the socket is not on the node we're deleting. */
if (link->tonode != node && link->tosock->flag & SOCK_MULTI_INPUT) {
adjust_multi_input_indices_after_removed_link(
ntree, link->tosock, link->multi_input_socket_index);
}
LISTBASE_FOREACH (const bNodeSocket *, sock, lb) {
if (link->fromsock == sock || link->tosock == sock) {
nodeRemLink(ntree, link);
break;
}
}
}
}