[Bf-blender-cvs] [ff15edc6ab4] master: Cleanup: unify method parameters for virtual arrays
Jacques Lucke
noreply at git.blender.org
Sat Jan 14 19:14:04 CET 2023
Commit: ff15edc6ab4add3a814f8f80c2a96b1a67def65c
Author: Jacques Lucke
Date: Sat Jan 14 19:13:51 2023 +0100
Branches: master
https://developer.blender.org/rBff15edc6ab4add3a814f8f80c2a96b1a67def65c
Cleanup: unify method parameters for virtual arrays
This makes `GVArrayImpl` and `VArrayImpl` more similar.
Only passing the pointer instead of the span also increases
efficiency a little bit. The downside is that a few asserts had
to be removed as well. However, in practice the same asserts
are in place at a higher level as well (in `VArrayCommon`).
===================================================================
M source/blender/blenkernel/intern/geometry_component_mesh.cc
M source/blender/blenlib/BLI_generic_virtual_array.hh
M source/blender/blenlib/BLI_virtual_array.hh
===================================================================
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index 7b694be324a..bdb1b0edf8b 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -984,26 +984,26 @@ class VArrayImpl_For_VertexWeights final : public VMutableArrayImpl<float> {
});
}
- void materialize(IndexMask mask, MutableSpan<float> r_span) const override
+ void materialize(IndexMask mask, float *dst) const override
{
if (dverts_ == nullptr) {
- return r_span.fill_indices(mask, 0.0f);
+ mask.foreach_index([&](const int i) { dst[i] = 0.0f; });
}
threading::parallel_for(mask.index_range(), 4096, [&](const IndexRange range) {
for (const int64_t i : mask.slice(range)) {
if (const MDeformWeight *weight = this->find_weight_at_index(i)) {
- r_span[i] = weight->weight;
+ dst[i] = weight->weight;
}
else {
- r_span[i] = 0.0f;
+ dst[i] = 0.0f;
}
}
});
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<float> r_span) const override
+ void materialize_to_uninitialized(IndexMask mask, float *dst) const override
{
- this->materialize(mask, r_span);
+ this->materialize(mask, dst);
}
private:
diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh b/source/blender/blenlib/BLI_generic_virtual_array.hh
index cba767341c1..cb45da5e495 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -388,25 +388,24 @@ template<typename T> class VArrayImpl_For_GVArray : public VArrayImpl<T> {
return true;
}
- void materialize(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize(IndexMask mask, T *dst) const override
{
- varray_.materialize(mask, r_span.data());
+ varray_.materialize(mask, dst);
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_to_uninitialized(IndexMask mask, T *dst) const override
{
- varray_.materialize_to_uninitialized(mask, r_span.data());
+ varray_.materialize_to_uninitialized(mask, dst);
}
- void materialize_compressed(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_compressed(IndexMask mask, T *dst) const override
{
- varray_.materialize_compressed(mask, r_span.data());
+ varray_.materialize_compressed(mask, dst);
}
- void materialize_compressed_to_uninitialized(IndexMask mask,
- MutableSpan<T> r_span) const override
+ void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const override
{
- varray_.materialize_compressed_to_uninitialized(mask, r_span.data());
+ varray_.materialize_compressed_to_uninitialized(mask, dst);
}
};
@@ -539,25 +538,24 @@ template<typename T> class VMutableArrayImpl_For_GVMutableArray : public VMutabl
return true;
}
- void materialize(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize(IndexMask mask, T *dst) const override
{
- varray_.materialize(mask, r_span.data());
+ varray_.materialize(mask, dst);
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_to_uninitialized(IndexMask mask, T *dst) const override
{
- varray_.materialize_to_uninitialized(mask, r_span.data());
+ varray_.materialize_to_uninitialized(mask, dst);
}
- void materialize_compressed(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_compressed(IndexMask mask, T *dst) const override
{
- varray_.materialize_compressed(mask, r_span.data());
+ varray_.materialize_compressed(mask, dst);
}
- void materialize_compressed_to_uninitialized(IndexMask mask,
- MutableSpan<T> r_span) const override
+ void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const override
{
- varray_.materialize_compressed_to_uninitialized(mask, r_span.data());
+ varray_.materialize_compressed_to_uninitialized(mask, dst);
}
};
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 189cb85d468..819807843df 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -107,17 +107,16 @@ template<typename T> class VArrayImpl {
* Copy values from the virtual array into the provided span. The index of the value in the
* virtual array is the same as the index in the span.
*/
- virtual void materialize(IndexMask mask, MutableSpan<T> r_span) const
+ virtual void materialize(IndexMask mask, T *dst) const
{
- mask.foreach_index([&](const int64_t i) { r_span[i] = this->get(i); });
+ mask.foreach_index([&](const int64_t i) { dst[i] = this->get(i); });
}
/**
* Same as #materialize but #r_span is expected to be uninitialized.
*/
- virtual void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const
+ virtual void materialize_to_uninitialized(IndexMask mask, T *dst) const
{
- T *dst = r_span.data();
mask.foreach_index([&](const int64_t i) { new (dst + i) T(this->get(i)); });
}
@@ -126,12 +125,11 @@ template<typename T> class VArrayImpl {
* in virtual array is not the same as the index in the output span. Instead, the span is filled
* without gaps.
*/
- virtual void materialize_compressed(IndexMask mask, MutableSpan<T> r_span) const
+ virtual void materialize_compressed(IndexMask mask, T *dst) const
{
- BLI_assert(mask.size() == r_span.size());
mask.to_best_mask_type([&](auto best_mask) {
for (const int64_t i : IndexRange(best_mask.size())) {
- r_span[i] = this->get(best_mask[i]);
+ dst[i] = this->get(best_mask[i]);
}
});
}
@@ -139,10 +137,8 @@ template<typename T> class VArrayImpl {
/**
* Same as #materialize_compressed but #r_span is expected to be uninitialized.
*/
- virtual void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const
+ virtual void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const
{
- BLI_assert(mask.size() == r_span.size());
- T *dst = r_span.data();
mask.to_best_mask_type([&](auto best_mask) {
for (const int64_t i : IndexRange(best_mask.size())) {
new (dst + i) T(this->get(best_mask[i]));
@@ -254,32 +250,27 @@ template<typename T> class VArrayImpl_For_Span : public VMutableArrayImpl<T> {
return data_ == static_cast<const T *>(other_info.data);
}
- void materialize(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize(IndexMask mask, T *dst) const override
{
- mask.foreach_index([&](const int64_t i) { r_span[i] = data_[i]; });
+ mask.foreach_index([&](const int64_t i) { dst[i] = data_[i]; });
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_to_uninitialized(IndexMask mask, T *dst) const override
{
- T *dst = r_span.data();
mask.foreach_index([&](const int64_t i) { new (dst + i) T(data_[i]); });
}
- void materialize_compressed(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_compressed(IndexMask mask, T *dst) const override
{
- BLI_assert(mask.size() == r_span.size());
mask.to_best_mask_type([&](auto best_mask) {
for (const int64_t i : IndexRange(best_mask.size())) {
- r_span[i] = data_[best_mask[i]];
+ dst[i] = data_[best_mask[i]];
}
});
}
- void materialize_compressed_to_uninitialized(IndexMask mask,
- MutableSpan<T> r_span) const override
+ void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const override
{
- BLI_assert(mask.size() == r_span.size());
- T *dst = r_span.data();
mask.to_best_mask_type([&](auto best_mask) {
for (const int64_t i : IndexRange(best_mask.size())) {
new (dst + i) T(data_[best_mask[i]]);
@@ -357,29 +348,24 @@ template<typename T> class VArrayImpl_For_Single final : public VArrayImpl<T> {
return CommonVArrayInfo(CommonVArrayInfo::Type::Single, true, &value_);
}
- void materialize(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize(IndexMask mask, T *dst) const override
{
- r_span.fill_indices(mask, value_);
+ mask.foreach_index([&](const int64_t i) { dst[i] = value_; });
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_to_uninitialized(IndexMask mask, T *dst) const override
{
- T *dst = r_span.data();
mask.foreach_index([&](const int64_t i) { new (dst + i) T(value_); });
}
- void materialize_compressed(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize_compressed(IndexMask mask, T *dst) const override
{
- BLI_assert(mask.size() == r_span.size());
- UNUSED_VARS_NDEBUG(mask);
- r_span.fill(value_);
+ initialized_fill_n(dst, mask.size(), value_);
}
- void materialize_compressed_to_uninitialized(IndexMask mask,
- MutableSpan<T> r_span) const override
+ void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const override
{
- BLI_assert(mask.size() == r_span.size());
- uninitialized_fill_n(r_span.data(), mask.size(), value_);
+ uninitialized_fill_n(dst, mask.size(), value_);
}
};
@@ -406,22 +392,18 @@ template<typename T, typename GetFunc> class VArrayImpl_For_Func final : public
return get_func_(index);
}
- void materialize(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize(IndexMask mask, T *dst) const override
{
- T *dst = r_span.data();
mask.foreach_index([&](const int64_t i) { dst[i] = get_func_(i); });
}
- void materialize_to_uninitialized(IndexMask mask, MutableSpan<T> r_span) const override
+ void materialize
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list