Cleanup: Use Array for FieldInferencingInterface

There is no need for amortized growth for the field interface.
Array seems slightly better than Vector because it's smaller and
doesn't give the impression that the size might change.

Pull Request: https://projects.blender.org/blender/blender/pulls/135257
This commit is contained in:
Hans Goudey
2025-02-27 17:32:51 +01:00
committed by Hans Goudey
parent b05fb3801e
commit 582cdc0cf2
3 changed files with 31 additions and 15 deletions

View File

@@ -106,10 +106,10 @@ static const FieldInferencingInterface &get_dummy_field_inferencing_interface(co
ResourceScope &scope)
{
auto &inferencing_interface = scope.construct<FieldInferencingInterface>();
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<InputSocketFieldType>(node.input_sockets().size(),
InputSocketFieldType::None);
inferencing_interface.outputs = Array<OutputFieldDependency>(
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<FieldInferencingInterface>();
for (const bNodeSocket *input_socket : node.input_sockets()) {
inferencing_interface.inputs.append(get_interface_input_field_type(node, *input_socket));
const Span<const bNodeSocket *> 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<const bNodeSocket *> 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<FieldInferencingInterface> new_inferencing_interface =
std::make_unique<FieldInferencingInterface>();
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<InputSocketFieldType>(
tree.interface_inputs().size(), InputSocketFieldType::IsSupported);
new_inferencing_interface->outputs = Array<OutputFieldDependency>(
tree.interface_outputs().size(), OutputFieldDependency::ForDataSource());
/* Keep track of the state of all sockets. The index into this array is #SocketRef::id(). */
Array<SocketFieldState> field_state_by_socket_id(tree.all_sockets().size());

View File

@@ -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.

View File

@@ -8,6 +8,7 @@
#include <functional>
#include <type_traits>
#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<InputSocketFieldType> inputs;
Vector<OutputFieldDependency> outputs;
Array<InputSocketFieldType> inputs;
Array<OutputFieldDependency> outputs;
BLI_STRUCT_EQUALITY_OPERATORS_2(FieldInferencingInterface, inputs, outputs)
};