[Bf-blender-cvs] [a48e5c53a54] master: Cleanup: Simplify const cast in virtual array construction

Hans Goudey noreply at git.blender.org
Tue Aug 2 20:44:23 CEST 2022


Commit: a48e5c53a546cd5e493a9e816ce9ed71f0e61a8b
Author: Hans Goudey
Date:   Tue Aug 2 13:44:07 2022 -0500
Branches: master
https://developer.blender.org/rBa48e5c53a546cd5e493a9e816ce9ed71f0e61a8b

Cleanup: Simplify const cast in virtual array construction

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

M	source/blender/blenlib/BLI_virtual_array.hh

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

diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 438fcc4b8f7..7eab960b302 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -315,6 +315,12 @@ template<typename T> class VArrayImpl_For_Span_final final : public VArrayImpl_F
  public:
   using VArrayImpl_For_Span<T>::VArrayImpl_For_Span;
 
+  VArrayImpl_For_Span_final(const Span<T> data)
+      /* Cast const away, because the implementation for const and non const spans is shared. */
+      : VArrayImpl_For_Span<T>({const_cast<T *>(data.data()), data.size()})
+  {
+  }
+
  private:
   CommonVArrayInfo common_info() const final
   {
@@ -898,10 +904,7 @@ template<typename T> class VArray : public VArrayCommon<T> {
 
   VArray(varray_tag::span /* tag */, Span<T> span)
   {
-    /* Cast const away, because the virtual array implementation for const and non const spans is
-     * shared. */
-    MutableSpan<T> mutable_span{const_cast<T *>(span.data()), span.size()};
-    this->template emplace<VArrayImpl_For_Span_final<T>>(mutable_span);
+    this->template emplace<VArrayImpl_For_Span_final<T>>(span);
   }
 
   VArray(varray_tag::single /* tag */, T value, const int64_t size)



More information about the Bf-blender-cvs mailing list