[Bf-blender-cvs] [098cb4ceaae] functions: cleanup copying ArrayRef to pointer
Jacques Lucke
noreply at git.blender.org
Fri Jun 21 16:56:36 CEST 2019
Commit: 098cb4ceaaee4681a131f5d0ffbadcc539d0052b
Author: Jacques Lucke
Date: Fri Jun 21 16:12:16 2019 +0200
Branches: functions
https://developer.blender.org/rB098cb4ceaaee4681a131f5d0ffbadcc539d0052b
cleanup copying ArrayRef to pointer
===================================================================
M source/blender/blenlib/BLI_array_ref.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
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 1f182d7e5ec..6a381398d54 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -96,6 +96,11 @@ template<typename T> class ArrayRef {
this->copy_from(other.begin());
}
+ void copy_to(T *ptr)
+ {
+ std::copy_n(m_start, m_size, ptr);
+ }
+
T *begin() const
{
return m_start;
@@ -117,6 +122,11 @@ template<typename T> class ArrayRef {
return m_size;
}
+ uint byte_size() const
+ {
+ return sizeof(T) * m_size;
+ }
+
bool contains(const T &value)
{
for (T &element : *this) {
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 5283393cb58..89588569a76 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -194,15 +194,16 @@ uint BParticles_state_particle_count(BParticlesState state_c)
return count;
}
-void BParticles_state_get_positions(BParticlesState state_c, float (*dst)[3])
+void BParticles_state_get_positions(BParticlesState state_c, float (*dst_c)[3])
{
ParticlesState &state = *unwrap(state_c);
+ float3 *dst = (float3 *)dst_c;
uint index = 0;
for (ParticlesContainer *container : state.particle_containers().values()) {
for (auto *block : container->active_blocks()) {
auto positions = block->slice_active().get_float3("Position");
- memcpy(dst + index, positions.begin(), sizeof(float3) * positions.size());
+ positions.copy_to(dst + index);
index += positions.size();
}
}
diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
index 6af0b26659c..5c6949ca85e 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -190,3 +190,23 @@ TEST(array_ref, CopyFrom)
EXPECT_EQ(a[1], 2);
EXPECT_EQ(a[2], 3);
}
+
+TEST(array_ref, ByteSize)
+{
+ std::array<int, 10> a;
+ IntArrayRef a_ref(a);
+ EXPECT_EQ(a_ref.byte_size(), sizeof(a));
+ EXPECT_EQ(a_ref.byte_size(), 40);
+}
+
+TEST(array_ref, CopyTo)
+{
+ std::array<int, 3> a = {5, 6, 7};
+ int b[3] = {0};
+ IntArrayRef a_ref(a);
+ a_ref.copy_to(b);
+
+ EXPECT_EQ(b[0], 5);
+ EXPECT_EQ(b[1], 6);
+ EXPECT_EQ(b[2], 7);
+}
More information about the Bf-blender-cvs
mailing list