[Bf-blender-cvs] [b7e193cdada] master: BLI: avoid unnecessary allocation when converting virtual array

Jacques Lucke noreply at git.blender.org
Sun Jun 19 14:53:00 CEST 2022


Commit: b7e193cdada3c5cf931a25283e7ad05ed38a2ec0
Author: Jacques Lucke
Date:   Sun Jun 19 14:52:51 2022 +0200
Branches: master
https://developer.blender.org/rBb7e193cdada3c5cf931a25283e7ad05ed38a2ec0

BLI: avoid unnecessary allocation when converting virtual array

===================================================================

M	source/blender/blenlib/BLI_generic_virtual_array.hh

===================================================================

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);



More information about the Bf-blender-cvs mailing list