[Bf-blender-cvs] [57ab7cefdd8] functions: introduce ScopedVector
Jacques Lucke
noreply at git.blender.org
Tue Dec 17 13:53:58 CET 2019
Commit: 57ab7cefdd8567793ed7ea8eaa8d0ba92beee123
Author: Jacques Lucke
Date: Tue Dec 17 11:48:33 2019 +0100
Branches: functions
https://developer.blender.org/rB57ab7cefdd8567793ed7ea8eaa8d0ba92beee123
introduce ScopedVector
===================================================================
M source/blender/blenlib/BLI_vector.h
M source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc
M source/blender/functions/intern/multi_functions/util.h
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index 96bb1e1e6bc..6d8471245f7 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -653,6 +653,12 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
*/
template<typename T, uint N = 4> using LargeScopedVector = Vector<T, N, TemporaryAllocator>;
+/**
+ * Use when the vector is used in the local scope of a function. It has a larger inline storage by
+ * default to make allocations less likely.
+ */
+template<typename T, uint N = 20> using ScopedVector = Vector<T, N, GuardedAllocator>;
+
} /* namespace BLI */
#endif /* __BLI_VECTOR_H__ */
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc
index 44e0d55cc9b..04683215b1b 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc
@@ -2,6 +2,8 @@
namespace FN {
+using BLI::ScopedVector;
+
InlinedTreeMFNetworkBuilder::InlinedTreeMFNetworkBuilder(
const InlinedNodeTree &inlined_tree,
const PreprocessedVTreeMFData &preprocessed_inlined_tree_data,
@@ -31,8 +33,8 @@ MFBuilderFunctionNode &InlinedTreeMFNetworkBuilder::add_function(const MultiFunc
MFBuilderDummyNode &InlinedTreeMFNetworkBuilder::add_dummy(const XNode &xnode)
{
- Vector<MFDataType> input_types;
- Vector<StringRef> input_names;
+ ScopedVector<MFDataType> input_types;
+ ScopedVector<StringRef> input_names;
for (const XInputSocket *xsocket : xnode.inputs()) {
Optional<MFDataType> data_type = this->try_get_data_type(*xsocket);
if (data_type.has_value()) {
@@ -41,8 +43,8 @@ MFBuilderDummyNode &InlinedTreeMFNetworkBuilder::add_dummy(const XNode &xnode)
}
}
- Vector<MFDataType> output_types;
- Vector<StringRef> output_names;
+ ScopedVector<MFDataType> output_types;
+ ScopedVector<StringRef> output_names;
for (const XOutputSocket *xsocket : xnode.outputs()) {
Optional<MFDataType> data_type = this->try_get_data_type(*xsocket);
if (data_type.has_value()) {
@@ -179,7 +181,7 @@ void VNodeMFNetworkBuilder::set_matching_fn(const MultiFunction &fn)
const MultiFunction &VNodeMFNetworkBuilder::get_vectorized_function(
const MultiFunction &base_function, ArrayRef<const char *> is_vectorized_prop_names)
{
- Vector<bool> input_is_vectorized;
+ ScopedVector<bool> input_is_vectorized;
for (const char *prop_name : is_vectorized_prop_names) {
char state[5];
RNA_string_get(m_xnode.rna(), prop_name, state);
diff --git a/source/blender/functions/intern/multi_functions/util.h b/source/blender/functions/intern/multi_functions/util.h
index 0c37fdfbc7c..2a2d39e0f51 100644
--- a/source/blender/functions/intern/multi_functions/util.h
+++ b/source/blender/functions/intern/multi_functions/util.h
@@ -5,6 +5,7 @@
namespace FN {
using BLI::LargeScopedVector;
+using BLI::ScopedVector;
template<typename T, typename FuncT, typename EqualFuncT = std::equal_to<T>>
void group_indices_by_same_value(ArrayRef<uint> indices,
@@ -21,7 +22,7 @@ void group_indices_by_same_value(ArrayRef<uint> indices,
return;
}
- Vector<T> seen_values;
+ ScopedVector<T> seen_values;
for (uint i : indices.index_iterator()) {
uint index = indices[i];
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index bc6b6072d13..6efb541df0c 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -38,6 +38,7 @@ using BLI::destruct_ptr;
using BLI::MultiMap;
using BLI::ResourceCollector;
using BLI::rgba_f;
+using BLI::ScopedVector;
using BLI::Set;
using FN::AttributesInfoBuilder;
using FN::CPPType;
@@ -116,7 +117,7 @@ class InlinedTreeData {
ParticleFunction *particle_function_for_all_inputs(const XNode &xnode)
{
- Vector<const MFInputSocket *> sockets_to_compute;
+ ScopedVector<const MFInputSocket *> sockets_to_compute;
for (const XInputSocket *xsocket : xnode.inputs()) {
if (m_inlined_tree_data_graph.is_mapped(*xsocket)) {
sockets_to_compute.append(&m_inlined_tree_data_graph.lookup_dummy_socket(*xsocket));
@@ -128,7 +129,7 @@ class InlinedTreeData {
ParticleFunction *particle_function_for_inputs(const XNode &xnode, ArrayRef<uint> input_indices)
{
- Vector<const MFInputSocket *> sockets_to_compute;
+ ScopedVector<const MFInputSocket *> sockets_to_compute;
for (uint i : input_indices) {
const MFInputSocket &socket = m_inlined_tree_data_graph.lookup_dummy_socket(xnode.input(i));
sockets_to_compute.append(&socket);
@@ -198,7 +199,7 @@ class InlinedTreeData {
Optional<NamedGenericTupleRef> compute_all_data_inputs(const XNode &xnode)
{
- Vector<uint> data_input_indices;
+ ScopedVector<uint> data_input_indices;
for (uint i : xnode.inputs().index_iterator()) {
if (m_inlined_tree_data_graph.is_mapped(xnode.input(i))) {
data_input_indices.append(i);
@@ -444,7 +445,7 @@ class XSocketActionBuilder {
const void *default_value = nullptr)
{
/* Add attribute to all particle systems for now. */
- Vector<std::string> system_names;
+ ScopedVector<std::string> system_names;
m_influences_collector.m_attributes.foreach_key(
[&](StringRef name) { system_names.append(name); });
More information about the Bf-blender-cvs
mailing list