# HG changeset patch
# User Petter .T <petter.vilhelm@gmail.com>
# Date 1701382071 -3600
#      Thu Nov 30 23:07:51 2023 +0100
# Node ID c5aab1a988efa88b88a9ca078f3af3e013689e4f
# Parent  a0e0ec128dcb5cedf3aa6ef4043309b86ad4d946
Move unused matrix in matrix assigns

A matrix to store the rhs arguments is constructed even when it
is not used.

* ov-base-mat.cc: (assign) Move matrix so that is only ctored if used.

diff -r a0e0ec128dcb -r c5aab1a988ef libinterp/octave-value/ov-base-mat.cc
--- a/libinterp/octave-value/ov-base-mat.cc	Thu Nov 30 23:04:15 2023 +0100
+++ b/libinterp/octave-value/ov-base-mat.cc	Thu Nov 30 23:07:51 2023 +0100
@@ -324,8 +324,6 @@
 
   int nd = m_matrix.ndims ();
 
-  MT mrhs (dim_vector (1, 1), rhs);
-
   // If we catch an indexing error in index_vector, we flag an error in
   // index k.  Ensure it is the right value before each idx_vector call.
   // Same variable as used in the for loop in the default case.
@@ -348,7 +346,10 @@
             if (i.is_scalar () && i(0) < m_matrix.numel ())
               m_matrix(i(0)) = rhs;
             else
-              m_matrix.assign (i, mrhs);
+              {
+                MT mrhs (dim_vector (1, 1), rhs);
+                m_matrix.assign (i, mrhs);
+              }
           }
           break;
 
@@ -364,7 +365,10 @@
                 && i(0) < m_matrix.rows () && j(0) < m_matrix.columns ())
               m_matrix(i(0), j(0)) = rhs;
             else
-              m_matrix.assign (i, j, mrhs);
+              {
+                MT mrhs (dim_vector (1, 1), rhs);
+                m_matrix.assign (i, j, mrhs);
+              }
           }
           break;
 
@@ -396,7 +400,10 @@
                 m_matrix(j) = rhs;
               }
             else
-              m_matrix.assign (idx_vec, mrhs);
+              {
+                MT mrhs (dim_vector (1, 1), rhs);
+                m_matrix.assign (idx_vec, mrhs);
+              }
           }
           break;
         }
