[Bf-blender-cvs] [2835c8df6f9] functions: allow SmallVector to use ArrayRef
Jacques Lucke
noreply at git.blender.org
Fri Jun 28 10:38:18 CEST 2019
Commit: 2835c8df6f9051d57fc0aada59e05feacadceebd
Author: Jacques Lucke
Date: Fri Jun 28 09:59:32 2019 +0200
Branches: functions
https://developer.blender.org/rB2835c8df6f9051d57fc0aada59e05feacadceebd
allow SmallVector to use ArrayRef
===================================================================
M source/blender/blenlib/BLI_array_ref.hpp
M source/blender/blenlib/BLI_small_vector.hpp
M source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
M source/blender/functions/backends/tuple/tuple.hpp
M source/blender/functions/core/function.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M source/blender/functions/functions/auto_vectorization.cpp
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/core.hpp
M tests/gtests/blenlib/BLI_array_ref_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_array_ref.hpp b/source/blender/blenlib/BLI_array_ref.hpp
index d8c4d43821b..1cfd2cfdac7 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -29,8 +29,9 @@
#include <vector>
#include <array>
+#include <algorithm>
-#include "BLI_small_vector.hpp"
+#include "BLI_utildefines.h"
namespace BLI {
@@ -61,11 +62,6 @@ template<typename T> class ArrayRef {
{
}
- template<uint N>
- ArrayRef(const SmallVector<T, N> &vector) : ArrayRef(vector.begin(), vector.size())
- {
- }
-
ArrayRef(const std::initializer_list<T> &list) : ArrayRef((T *)list.begin(), list.size())
{
}
@@ -214,18 +210,6 @@ template<typename T> class ArrayRef {
}
return counter;
}
-
- /**
- * Create a new SmallVector based on the referenced array.
- */
- template<uint N = 4> SmallVector<T, N> to_small_vector() const
- {
- SmallVector<T, N> vector;
- for (T &value : *this) {
- vector.append(value);
- }
- return vector;
- }
};
template<typename ArrayT, typename ValueT, ValueT (*GetValue)(ArrayT &item)> class MappedArrayRef {
diff --git a/source/blender/blenlib/BLI_small_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
index 4823b1dfb1a..b52d573f4f5 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -33,6 +33,8 @@
#include <memory>
#include "BLI_utildefines.h"
+#include "BLI_array_ref.hpp"
+
#include "MEM_guardedalloc.h"
namespace BLI {
@@ -90,7 +92,14 @@ template<typename T, uint N = 4> class SmallVector {
/**
* Create a vector from an initializer list.
*/
- SmallVector(std::initializer_list<T> values) : SmallVector()
+ SmallVector(std::initializer_list<T> values) : SmallVector(ArrayRef<T>(values))
+ {
+ }
+
+ /**
+ * Create a vector from an array ref.
+ */
+ SmallVector(ArrayRef<T> values) : SmallVector()
{
this->reserve(values.size());
std::uninitialized_copy_n(values.begin(), values.size(), this->begin());
@@ -122,6 +131,11 @@ template<typename T, uint N = 4> class SmallVector {
this->destruct_elements_and_free_memory();
}
+ operator ArrayRef<T>() const
+ {
+ return ArrayRef<T>(m_elements, m_size);
+ }
+
SmallVector &operator=(const SmallVector &other)
{
if (this == &other) {
diff --git a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
index c21b88834c0..f2a5f619cea 100644
--- a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
@@ -66,7 +66,7 @@ class TupleCallLLVM : public LLVMBuildIRBody {
builder, interface, settings, input_type_infos, output_type_infos);
/* Call wrapper function. */
- LLVMValues call_inputs = interface.inputs().to_small_vector();
+ LLVMValues call_inputs = interface.inputs();
if (settings.maintain_stack()) {
call_inputs.append(interface.context_ptr());
}
diff --git a/source/blender/functions/backends/tuple/tuple.hpp b/source/blender/functions/backends/tuple/tuple.hpp
index 5955eb19ded..b0268c5804d 100644
--- a/source/blender/functions/backends/tuple/tuple.hpp
+++ b/source/blender/functions/backends/tuple/tuple.hpp
@@ -14,7 +14,7 @@ class TupleMeta : public RefCountedBase {
bool m_all_trivially_destructible;
public:
- TupleMeta(ArrayRef<SharedType> types = {}) : m_types(types.to_small_vector())
+ TupleMeta(ArrayRef<SharedType> types = {}) : m_types(types)
{
m_all_trivially_destructible = true;
m_size__data = 0;
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index d015dd29199..fc72ffc764e 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -46,10 +46,10 @@ class Function final : public RefCountedBase {
ArrayRef<SharedType> output_types,
const char *strings)
: m_name(name),
- m_input_names(input_names.to_small_vector()),
- m_input_types(input_types.to_small_vector()),
- m_output_names(output_names.to_small_vector()),
- m_output_types(output_types.to_small_vector()),
+ m_input_names(input_names),
+ m_input_types(input_types),
+ m_output_names(output_names),
+ m_output_types(output_types),
m_strings(strings)
{
BLI_assert(m_input_names.size() == m_input_types.size());
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
index 283fb5dfe1d..499d837c72c 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
@@ -100,7 +100,7 @@ class SocketLoaderBody : public TupleCallBody {
SocketLoaderBody(bNodeTree *btree,
ArrayRef<bNodeSocket *> bsockets,
SmallVector<SocketLoader> &loaders)
- : m_btree(btree), m_bsockets(bsockets.to_small_vector()), m_loaders(loaders)
+ : m_btree(btree), m_bsockets(bsockets), m_loaders(loaders)
{
}
diff --git a/source/blender/functions/functions/auto_vectorization.cpp b/source/blender/functions/functions/auto_vectorization.cpp
index c98e60b7b1b..021bcb99143 100644
--- a/source/blender/functions/functions/auto_vectorization.cpp
+++ b/source/blender/functions/functions/auto_vectorization.cpp
@@ -50,8 +50,8 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
ArrayRef<bool> input_is_list,
ArrayRef<SharedFunction> empty_list_value_builders)
: m_main(main),
- m_input_is_list(input_is_list.to_small_vector()),
- m_empty_list_value_builders(empty_list_value_builders.to_small_vector())
+ m_input_is_list(input_is_list),
+ m_empty_list_value_builders(empty_list_value_builders)
{
BLI_assert(input_is_list.contains(true));
for (uint i = 0; i < main->input_amount(); i++) {
@@ -466,8 +466,8 @@ struct AutoVectorizationInput {
ArrayRef<bool> vectorized_inputs_mask,
ArrayRef<SharedFunction> empty_list_value_builders)
: m_original_fn(original_fn),
- m_vectorized_inputs_mask(vectorized_inputs_mask.to_small_vector()),
- m_empty_list_value_builders(empty_list_value_builders.to_small_vector())
+ m_vectorized_inputs_mask(vectorized_inputs_mask),
+ m_empty_list_value_builders(empty_list_value_builders)
{
}
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index d5b0cfd1358..914bb38db02 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -27,7 +27,7 @@ AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
}
AttributeArraysCore::AttributeArraysCore(AttributesInfo &info, ArrayRef<void *> arrays, uint size)
- : m_info(&info), m_arrays(arrays.to_small_vector()), m_size(size)
+ : m_info(&info), m_arrays(arrays), m_size(size)
{
}
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index e8596e97930..ca2b808b8a8 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -102,8 +102,8 @@ class EmitTarget {
ArrayRef<Range<uint>> ranges)
: m_particle_type_id(particle_type_id),
m_attributes_info(attributes_info),
- m_blocks(blocks.to_small_vector()),
- m_ranges(ranges.to_small_vector())
+ m_blocks(blocks),
+ m_ranges(ranges)
{
BLI_assert(blocks.size() == ranges.size());
for (auto range : ranges) {
diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
index 5c6949ca85e..af4c31c6018 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -1,5 +1,6 @@
#include "testing/testing.h"
#include "BLI_array_ref.hpp"
+#include "BLI_small_vector.hpp"
using IntVector = BLI::SmallVector<int>;
using IntArrayRef = BLI::ArrayRef<int>;
@@ -118,7 +119,7 @@ TEST(array_ref, ToSmallVector)
{
IntVector a = {1, 2, 3, 4};
IntArrayRef a_ref = a;
- IntVector b = a_ref.to_small_vector();
+ IntVector b = a_ref;
IntVector::all_equal(a, b);
}
More information about the Bf-blender-cvs
mailing list