[Bf-blender-cvs] [f7c0f1b8b83] master: BLI: rename ArrayRef to Span
Jacques Lucke
noreply at git.blender.org
Tue Jun 9 12:02:17 CEST 2020
Commit: f7c0f1b8b83ac475755b633abf59cf9f447b2d49
Author: Jacques Lucke
Date: Tue Jun 9 11:58:47 2020 +0200
Branches: master
https://developer.blender.org/rBf7c0f1b8b83ac475755b633abf59cf9f447b2d49
BLI: rename ArrayRef to Span
This also renames `MutableArrayRef` to `MutableSpan`.
The name "Span" works better, because `std::span` will provide
similar functionality in C++20. Furthermore, a shorter, more
concise name for a common data structure is nice.
===================================================================
M source/blender/blenkernel/intern/simulation.cc
M source/blender/blenlib/BLI_array.hh
M source/blender/blenlib/BLI_dot_export.hh
M source/blender/blenlib/BLI_index_mask.hh
M source/blender/blenlib/BLI_index_range.hh
M source/blender/blenlib/BLI_linear_allocator.hh
M source/blender/blenlib/BLI_set.hh
R067 source/blender/blenlib/BLI_array_ref.hh source/blender/blenlib/BLI_span.hh
M source/blender/blenlib/BLI_stack.hh
M source/blender/blenlib/BLI_string_ref.hh
M source/blender/blenlib/BLI_vector.hh
M source/blender/blenlib/BLI_vector_set.hh
M source/blender/blenlib/CMakeLists.txt
M source/blender/blenlib/intern/BLI_index_range.cc
M source/blender/blenlib/intern/dot_export.cc
M source/blender/depsgraph/intern/depsgraph_registry.cc
M source/blender/depsgraph/intern/depsgraph_registry.h
M source/blender/depsgraph/intern/depsgraph_type.h
M source/blender/modifiers/intern/MOD_mask.cc
D tests/gtests/blenlib/BLI_array_ref_test.cc
M tests/gtests/blenlib/BLI_array_test.cc
M tests/gtests/blenlib/BLI_index_mask_test.cc
M tests/gtests/blenlib/BLI_index_range_test.cc
M tests/gtests/blenlib/BLI_linear_allocator_test.cc
A tests/gtests/blenlib/BLI_span_test.cc
M tests/gtests/blenlib/BLI_stack_cxx_test.cc
M tests/gtests/blenlib/BLI_vector_test.cc
M tests/gtests/blenlib/CMakeLists.txt
===================================================================
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index 8f08665ab8a..20a23ab8b38 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -27,11 +27,11 @@
#include "DNA_scene_types.h"
#include "DNA_simulation_types.h"
-#include "BLI_array_ref.hh"
#include "BLI_compiler_compat.h"
#include "BLI_float3.hh"
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_span.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -54,9 +54,9 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
-using blender::ArrayRef;
using blender::float3;
-using blender::MutableArrayRef;
+using blender::MutableSpan;
+using blender::Span;
static void simulation_init_data(ID *id)
{
@@ -168,9 +168,9 @@ void *BKE_simulation_add(Main *bmain, const char *name)
return simulation;
}
-static MutableArrayRef<float3> get_particle_positions(ParticleSimulationState *state)
+static MutableSpan<float3> get_particle_positions(ParticleSimulationState *state)
{
- return MutableArrayRef<float3>(
+ return MutableSpan<float3>(
(float3 *)CustomData_get_layer_named(&state->attributes, CD_LOCATION, "Position"),
state->tot_particles);
}
@@ -239,7 +239,7 @@ void BKE_simulation_data_update(Depsgraph *depsgraph, Scene *scene, Simulation *
CustomData_realloc(&state_orig->attributes, state_orig->tot_particles);
ensure_attributes_exist(state_orig);
- MutableArrayRef<float3> positions = get_particle_positions(state_orig);
+ MutableSpan<float3> positions = get_particle_positions(state_orig);
for (uint i : positions.index_range()) {
positions[i] = {i / 10.0f, 0, 0};
}
@@ -250,7 +250,7 @@ void BKE_simulation_data_update(Depsgraph *depsgraph, Scene *scene, Simulation *
else if (current_frame == state_orig->current_frame + 1) {
state_orig->current_frame = current_frame;
ensure_attributes_exist(state_orig);
- MutableArrayRef<float3> positions = get_particle_positions(state_orig);
+ MutableSpan<float3> positions = get_particle_positions(state_orig);
for (float3 &position : positions) {
position.z += 0.1f;
}
diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh
index 874cd6b215a..b929d1220da 100644
--- a/source/blender/blenlib/BLI_array.hh
+++ b/source/blender/blenlib/BLI_array.hh
@@ -39,9 +39,9 @@
*/
#include "BLI_allocator.hh"
-#include "BLI_array_ref.hh"
#include "BLI_index_range.hh"
#include "BLI_memory_utils.hh"
+#include "BLI_span.hh"
#include "BLI_utildefines.h"
namespace blender {
@@ -90,7 +90,7 @@ class Array {
/**
* Create a new array that contains copies of all values.
*/
- Array(ArrayRef<T> values)
+ Array(Span<T> values)
{
m_size = values.size();
m_data = this->get_buffer_for_size(values.size());
@@ -100,7 +100,7 @@ class Array {
/**
* Create a new array that contains copies of all values.
*/
- Array(const std::initializer_list<T> &values) : Array(ArrayRef<T>(values))
+ Array(const std::initializer_list<T> &values) : Array(Span<T>(values))
{
}
@@ -184,22 +184,22 @@ class Array {
return *this;
}
- operator ArrayRef<T>() const
+ operator Span<T>() const
{
- return ArrayRef<T>(m_data, m_size);
+ return Span<T>(m_data, m_size);
}
- operator MutableArrayRef<T>()
+ operator MutableSpan<T>()
{
- return MutableArrayRef<T>(m_data, m_size);
+ return MutableSpan<T>(m_data, m_size);
}
- ArrayRef<T> as_ref() const
+ Span<T> as_span() const
{
return *this;
}
- MutableArrayRef<T> as_mutable_ref()
+ MutableSpan<T> as_mutable_span()
{
return *this;
}
@@ -243,9 +243,9 @@ class Array {
/**
* Copies the value to the given indices in the array.
*/
- void fill_indices(ArrayRef<uint> indices, const T &value)
+ void fill_indices(Span<uint> indices, const T &value)
{
- MutableArrayRef<T>(*this).fill_indices(indices, value);
+ MutableSpan<T>(*this).fill_indices(indices, value);
}
/**
diff --git a/source/blender/blenlib/BLI_dot_export.hh b/source/blender/blenlib/BLI_dot_export.hh
index 60353d7913f..67af4391a55 100644
--- a/source/blender/blenlib/BLI_dot_export.hh
+++ b/source/blender/blenlib/BLI_dot_export.hh
@@ -267,8 +267,8 @@ class NodeWithSocketsRef {
public:
NodeWithSocketsRef(Node &node,
StringRef name,
- ArrayRef<std::string> input_names,
- ArrayRef<std::string> output_names);
+ Span<std::string> input_names,
+ Span<std::string> output_names);
NodePort input(uint index) const
{
diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh
index 4cd348215fe..cc1bf05f936 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -38,15 +38,15 @@
* same time.
*/
-#include "BLI_array_ref.hh"
#include "BLI_index_range.hh"
+#include "BLI_span.hh"
namespace blender {
class IndexMask {
private:
/* The underlying reference to sorted integers. */
- ArrayRef<uint> m_indices;
+ Span<uint> m_indices;
public:
/* Creates an IndexMask that contains no indices. */
@@ -57,7 +57,7 @@ class IndexMask {
* This constructor asserts that the given integers are in ascending order and that there are no
* duplicates.
*/
- IndexMask(ArrayRef<uint> indices) : m_indices(indices)
+ IndexMask(Span<uint> indices) : m_indices(indices)
{
#ifdef DEBUG
for (uint i = 1; i < indices.size(); i++) {
@@ -70,7 +70,7 @@ class IndexMask {
* Use this method when you know that no indices are skipped. It is more efficient than preparing
* an integer array all the time.
*/
- IndexMask(IndexRange range) : m_indices(range.as_array_ref())
+ IndexMask(IndexRange range) : m_indices(range.as_span())
{
}
@@ -84,7 +84,7 @@ class IndexMask {
* Do this:
* do_something_with_an_index_mask({3, 4, 5});
*/
- IndexMask(const std::initializer_list<uint> &indices) : IndexMask(ArrayRef<uint>(indices))
+ IndexMask(const std::initializer_list<uint> &indices) : IndexMask(Span<uint>(indices))
{
}
@@ -95,7 +95,7 @@ class IndexMask {
{
}
- operator ArrayRef<uint>() const
+ operator Span<uint>() const
{
return m_indices;
}
@@ -133,7 +133,7 @@ class IndexMask {
}
}
- ArrayRef<uint> indices() const
+ Span<uint> indices() const
{
return m_indices;
}
diff --git a/source/blender/blenlib/BLI_index_range.hh b/source/blender/blenlib/BLI_index_range.hh
index 8a97facd9c0..25192429a5d 100644
--- a/source/blender/blenlib/BLI_index_range.hh
+++ b/source/blender/blenlib/BLI_index_range.hh
@@ -49,7 +49,7 @@
* Ideally this could be could be even closer to Python's enumerate(). We might get that in the
* future with newer C++ versions.
*
- * One other important feature is the as_array_ref method. This method returns an ArrayRef<uint>
+ * One other important feature is the as_span method. This method returns an Span<uint>
* that contains the interval as individual numbers.
*/
@@ -66,7 +66,7 @@ template<typename Value> class blocked_range;
namespace blender {
-template<typename T> class ArrayRef;
+template<typename T> class Span;
class IndexRange {
private:
@@ -227,7 +227,7 @@ class IndexRange {
/**
* Get read-only access to a memory buffer that contains the range as actual numbers.
*/
- ArrayRef<uint> as_array_ref() const;
+ Span<uint> as_span() const;
friend std::ostream &operator<<(std::ostream &stream, IndexRange range)
{
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh
index e2bb3ce02cb..f968f9f15ce 100644
--- a/source/blender/blenlib/BLI_linear_allocator.hh
+++ b/source/blender/blenlib/BLI_linear_allocator.hh
@@ -35,7 +35,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
private:
Allocator m_allocator;
Vector<void *> m_owned_buffers;
- Vector<ArrayRef<char>> m_unused_borrowed_buffers;
+ Vector<Span<char>> m_unused_borrowed_buffers;
uintptr_t m_current_begin;
uintptr_t m_current_end;
@@ -104,9 +104,9 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
*
* This method only allocates memory and does not construct the instance.
*/
- template<typename T> MutableArrayRef<T> allocate_array(uint size)
+ template<typename T> MutableSpan<T> allocate_array(uint size)
{
- return MutableArrayRef<T>((T *)this->allocate(sizeof(T) * size, alignof(T)), size);
+ return MutableSpan<T>((T *)this->allocate(sizeof(T) * size, alignof(T)), size);
}
/**
@@ -127,9 +127,9 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
/**
* Copy the given array into a memory buffer provided by this allocator.
*/
- template<typename T> MutableArrayRef<T> construct_array_copy(ArrayRef<T> src)
+ template<typename T> MutableSpan<T> construct_array_copy(Span<T> src)
{
- MutableArrayRef<T> dst = this->allocate_array<T>(src.size());
+ MutableSpan<T> dst = this->allocate_array<T>(src.size());
uninitialized_copy_n(src.data(), src.size(), dst.data());
return dst;
}
@@ -146,14 +146,14 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
return StringRefNull((const char *)buffer);
}
- MutableArrayRef<void *> allocate_elements_and_pointer_array(uint element_amount,
- uint element_size,
- uint element_alignment)
+ MutableSpan<void *> allocate_elements_and_pointer_array(uint element_amount,
+ uint element_size,
+ uint element_alignment)
{
void *pointer_buffer = this->allocate(element_amount * sizeof(void *), alignof(void *));
void *elements_buffer = this->allocate(element_amount * element_size, element_alignment);
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list