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>2022-06-19 15:52:51 +0300
committerJacques Lucke <jacques@blender.org>2022-06-19 15:52:51 +0300
commitb7e193cdada3c5cf931a25283e7ad05ed38a2ec0 (patch)
tree67461a9a6fc626058877e3101f80e85960f46cb2
parentd48735cca2c69cefa7d4cdf3128cfdcd1beeb909 (diff)
BLI: avoid unnecessary allocation when converting virtual array
-rw-r--r--source/blender/blenlib/BLI_generic_virtual_array.hh18
1 files changed, 9 insertions, 9 deletions
diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh b/source/blender/blenlib/BLI_generic_virtual_array.hh
index 3fce2947d0d..985d914f4a4 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -934,15 +934,15 @@ template<typename T> inline GVArray::GVArray(const VArray<T> &varray)
if (varray.try_assign_GVArray(*this)) {
return;
}
- /* Need to check this before the span/single special cases, because otherwise we might loose
- * ownership to the referenced data when #varray goes out of scope. */
- if (varray.may_have_ownership()) {
- *this = GVArray::For<GVArrayImpl_For_VArray<T>>(varray);
- }
- else if (varray.is_single()) {
+ if (varray.is_single()) {
T value = varray.get_internal_single();
*this = GVArray::ForSingle(CPPType::get<T>(), varray.size(), &value);
}
+ /* Need to check this before the span special case, because otherwise we might loose
+ * ownership to the referenced data when #varray goes out of scope. */
+ else if (varray.may_have_ownership()) {
+ *this = GVArray::For<GVArrayImpl_For_VArray<T>>(varray);
+ }
else if (varray.is_span()) {
Span<T> data = varray.get_internal_span();
*this = GVArray::ForSpan(data);
@@ -962,14 +962,14 @@ template<typename T> inline VArray<T> GVArray::typed() const
if (this->try_assign_VArray(varray)) {
return varray;
}
- if (this->may_have_ownership()) {
- return VArray<T>::template For<VArrayImpl_For_GVArray<T>>(*this);
- }
if (this->is_single()) {
T value;
this->get_internal_single(&value);
return VArray<T>::ForSingle(value, this->size());
}
+ if (this->may_have_ownership()) {
+ return VArray<T>::template For<VArrayImpl_For_GVArray<T>>(*this);
+ }
if (this->is_span()) {
const Span<T> span = this->get_internal_span().typed<T>();
return VArray<T>::ForSpan(span);