Skip to content

Commit e380e6f

Browse files
alphaditocarson-katri
authored andcommitted
precalculate number of links to node input sockets to avoid using the 'links' property
1 parent f0d43fb commit e380e6f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

api/arrange.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def topo_sort(graph):
2323
return topo_order
2424

2525
graph = { node:set() for node in node_tree.nodes }
26+
node_input_link_count = { i:0 for node in node_tree.nodes for i in node.inputs }
2627
for link in node_tree.links:
2728
graph[link.from_node].add(link.to_node)
29+
node_input_link_count[link.to_socket] += 1
2830
sorted_nodes = topo_sort(graph)
2931

3032
column_index = {}
@@ -52,7 +54,7 @@ def topo_sort(graph):
5254
output_count = len(list(filter(lambda i: i.enabled, node.outputs)))
5355
parent_props = [prop.identifier for base in type(node).__bases__ for prop in base.bl_rna.properties]
5456
properties_count = len([prop for prop in node.bl_rna.properties if prop.identifier not in parent_props])
55-
unset_vector_count = len(list(filter(lambda i: i.enabled and i.type == 'VECTOR' and len(i.links) == 0, node.inputs)))
57+
unset_vector_count = len(list(filter(lambda i: i.enabled and i.type == 'VECTOR' and node_input_link_count[i] == 0, node.inputs)))
5658
node_height = (
5759
NODE_HEADER_HEIGHT \
5860
+ (output_count * NODE_LINK_HEIGHT) \

0 commit comments

Comments
 (0)