diff --git a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc index a1ad072fde0..e0a78831cdc 100644 --- a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc +++ b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc @@ -106,10 +106,10 @@ static const FieldInferencingInterface &get_dummy_field_inferencing_interface(co ResourceScope &scope) { auto &inferencing_interface = scope.construct(); - inferencing_interface.inputs.append_n_times(InputSocketFieldType::None, - node.input_sockets().size()); - inferencing_interface.outputs.append_n_times(OutputFieldDependency::ForDataSource(), - node.output_sockets().size()); + inferencing_interface.inputs = Array(node.input_sockets().size(), + InputSocketFieldType::None); + inferencing_interface.outputs = Array( + node.output_sockets().size(), OutputFieldDependency::ForDataSource()); return inferencing_interface; } @@ -140,13 +140,18 @@ static const FieldInferencingInterface &get_node_field_inferencing_interface(con } auto &inferencing_interface = scope.construct(); - for (const bNodeSocket *input_socket : node.input_sockets()) { - inferencing_interface.inputs.append(get_interface_input_field_type(node, *input_socket)); + + const Span input_sockets = node.input_sockets(); + inferencing_interface.inputs.reinitialize(input_sockets.size()); + for (const int i : input_sockets.index_range()) { + inferencing_interface.inputs[i] = get_interface_input_field_type(node, *input_sockets[i]); } - for (const bNodeSocket *output_socket : node.output_sockets()) { - inferencing_interface.outputs.append( - get_interface_output_field_dependency(node, *output_socket)); + const Span output_sockets = node.output_sockets(); + inferencing_interface.outputs.reinitialize(output_sockets.size()); + for (const int i : output_sockets.index_range()) { + inferencing_interface.outputs[i] = get_interface_output_field_dependency(node, + *output_sockets[i]); } return inferencing_interface; } @@ -716,10 +721,10 @@ bool update_field_inferencing(const bNodeTree &tree) /* Create new inferencing interface for this node group. */ std::unique_ptr new_inferencing_interface = std::make_unique(); - new_inferencing_interface->inputs.resize(tree.interface_inputs().size(), - InputSocketFieldType::IsSupported); - new_inferencing_interface->outputs.resize(tree.interface_outputs().size(), - OutputFieldDependency::ForDataSource()); + new_inferencing_interface->inputs = Array( + tree.interface_inputs().size(), InputSocketFieldType::IsSupported); + new_inferencing_interface->outputs = Array( + tree.interface_outputs().size(), OutputFieldDependency::ForDataSource()); /* Keep track of the state of all sockets. The index into this array is #SocketRef::id(). */ Array field_state_by_socket_id(tree.all_sockets().size()); diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh index 552b9f5f52d..46a79d86475 100644 --- a/source/blender/blenlib/BLI_array.hh +++ b/source/blender/blenlib/BLI_array.hh @@ -351,6 +351,16 @@ class Array { return IndexRange(size_); } + friend bool operator==(const Array &a, const Array &b) + { + return a.as_span() == b.as_span(); + } + + friend bool operator!=(const Array &a, const Array &b) + { + return !(a == b); + } + /** * Sets the size to zero. This should only be used when you have manually destructed all elements * in the array beforehand. Use with care. diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh index ee65c3d297b..8adbaec863d 100644 --- a/source/blender/nodes/NOD_node_declaration.hh +++ b/source/blender/nodes/NOD_node_declaration.hh @@ -8,6 +8,7 @@ #include #include +#include "BLI_array.hh" #include "BLI_string_ref.hh" #include "BLI_utildefines.h" #include "BLI_vector.hh" @@ -80,8 +81,8 @@ class OutputFieldDependency { * Information about how a node interacts with fields. */ struct FieldInferencingInterface { - Vector inputs; - Vector outputs; + Array inputs; + Array outputs; BLI_STRUCT_EQUALITY_OPERATORS_2(FieldInferencingInterface, inputs, outputs) };