[Bf-blender-cvs] [c5d38a2be8e] master: Functions: Expose set_all method for generic virtual arrays
Hans Goudey
noreply at git.blender.org
Fri May 14 00:47:56 CEST 2021
Commit: c5d38a2be8e746379181dd1accb184e762459a29
Author: Hans Goudey
Date: Thu May 13 17:47:46 2021 -0500
Branches: master
https://developer.blender.org/rBc5d38a2be8e746379181dd1accb184e762459a29
Functions: Expose set_all method for generic virtual arrays
This is very similar to rB5613c61275fe6 and rB0061150e4c90d, basically
just exposing a `VMutableArray` method to its generic counterpart. This
is quite important for curve point attributes to avoid a lookup for
every point when there are multiple splines.
===================================================================
M source/blender/functions/FN_generic_virtual_array.hh
M source/blender/functions/intern/generic_virtual_array.cc
===================================================================
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 12454fe08f3..31f649e0358 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -220,11 +220,19 @@ class GVMutableArray : public GVArray {
void fill(const void *value);
+ /* Copy the values from the source buffer to all elements in the virtual array. */
+ void set_all(const void *src)
+ {
+ this->set_all_impl(src);
+ }
+
protected:
virtual void set_by_copy_impl(const int64_t index, const void *value);
virtual void set_by_relocate_impl(const int64_t index, void *value);
virtual void set_by_move_impl(const int64_t index, void *value) = 0;
+ virtual void set_all_impl(const void *src);
+
virtual void *try_get_internal_mutable_varray_impl();
};
@@ -554,6 +562,11 @@ template<typename T> class GVMutableArray_For_VMutableArray : public GVMutableAr
varray_->set(index, std::move(value_));
}
+ void set_all_impl(const void *src)
+ {
+ varray_->set_all(Span((T *)data, size_));
+ }
+
void materialize_impl(const IndexMask mask, void *dst) const override
{
varray_->materialize(mask, MutableSpan((T *)dst, mask.min_array_size()));
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index a835e7a54a9..87dae06ccdc 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -160,6 +160,19 @@ void GVMutableArray::set_by_relocate_impl(const int64_t index, void *value)
type_->destruct(value);
}
+void GVMutableArray::set_all_impl(const void *src)
+{
+ if (this->is_span()) {
+ const GMutableSpan span = this->get_internal_span();
+ type_->copy_to_initialized_n(src, span.data(), size_);
+ }
+ else {
+ for (int64_t i : IndexRange(size_)) {
+ this->set_by_copy(i, POINTER_OFFSET(src, type_->size() * i));
+ }
+ }
+}
+
void *GVMutableArray::try_get_internal_mutable_varray_impl()
{
return nullptr;
More information about the Bf-blender-cvs
mailing list