Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-09-26 15:11:42 +0300
committerJacques Lucke <jacques@blender.org>2021-09-26 15:11:42 +0300
commit34ed0de2879725f30d54499f312850b83855e861 (patch)
tree3feeefb18cb9b49e5d8e67a8f5d62e9043393d4f
parent3bcb30b13b6085c19e7173953beb899171d1e130 (diff)
improve
-rw-r--r--source/blender/blenlib/BLI_virtual_array.hh29
1 files changed, 28 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 8c348625226..3843f838767 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -658,6 +658,12 @@ class VArray_For_DerivedSpan : public VArray<ElemT> {
private:
const StructT *data_;
+ template<typename OtherStructT,
+ typename OtherElemT,
+ OtherElemT (*OtherGetFunc)(const OtherStructT &),
+ void (*OtherSetFunc)(OtherStructT &, OtherElemT)>
+ friend class VMutableArray_For_DerivedSpan;
+
public:
VArray_For_DerivedSpan(const Span<StructT> data) : VArray<ElemT>(data.size()), data_(data.data())
{
@@ -699,6 +705,9 @@ class VMutableArray_For_DerivedSpan : public VMutableArray<ElemT> {
private:
StructT *data_;
+ using SelfT = VMutableArray_For_DerivedSpan;
+ using ConstSelfT = const VArray_For_DerivedSpan<StructT, ElemT, GetFunc>;
+
public:
VMutableArray_For_DerivedSpan(const MutableSpan<StructT> data)
: VMutableArray<ElemT>(data.size()), data_(data.data())
@@ -747,6 +756,22 @@ class VMutableArray_For_DerivedSpan : public VMutableArray<ElemT> {
const ElemT src_value = src_varray.get_internal_single();
mask.foreach_index([&](const int64_t i) { SetFunc(data_[i], src_value); });
}
+ else if (const SelfT *src_varray_typed = dynamic_cast<const SelfT *>(&src_varray)) {
+ if (src_varray_typed->data_ == data_) {
+ /* Nothing to do. */
+ return;
+ }
+ mask.foreach_index(
+ [&](const int64_t i) { SetFunc(data_[i], GetFunc(src_varray_typed->data_[i])); });
+ }
+ else if (const ConstSelfT *src_varray_typed = dynamic_cast<const ConstSelfT *>(&src_varray)) {
+ if (src_varray_typed->data_ == data_) {
+ /* Nothing to do. */
+ return;
+ }
+ mask.foreach_index(
+ [&](const int64_t i) { SetFunc(data_[i], GetFunc(src_varray_typed->data_[i])); });
+ }
else {
mask.foreach_index([&](const int64_t i) { SetFunc(data_[i], src_varray.get(i)); });
}
@@ -754,7 +779,9 @@ class VMutableArray_For_DerivedSpan : public VMutableArray<ElemT> {
virtual bool can_set_multiple_efficiently_impl(const VArray<ElemT> &src_varray) const
{
- return src_varray.is_span() || src_varray.is_single();
+ return src_varray.is_span() || src_varray.is_single() ||
+ dynamic_cast<const SelfT *>(&src_varray) != nullptr ||
+ dynamic_cast<const ConstSelfT *>(&src_varray) != nullptr;
}
};