diff src/ov-cell.cc @ 8446:7b25349b32e6

avoid redundant copying in {} assignment
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 08 Jan 2009 22:12:17 +0100
parents 25bc2d31e1bf
children d6a349c7bd39
line wrap: on
line diff
--- a/src/ov-cell.cc	Mon Jan 05 21:33:54 2009 -0500
+++ b/src/ov-cell.cc	Thu Jan 08 22:12:17 2009 +0100
@@ -181,21 +181,20 @@
 	  {
 	    octave_value tmp = do_index_op (idx.front (), true);
 
-	    if (! tmp.is_defined ())
-	      tmp = octave_value::empty_conv (type.substr (1), rhs);
-
 	    if (! error_state)
 	      {
-		const Cell tcell = tmp.cell_value ();
+		if (tmp.dims ().numel () == 1)
+		  {
+		    tmp = tmp.cell_value ()(0,0);
 
-		if (! error_state && tcell.length () == 1)
-		  {
-		    tmp = tcell(0,0);
+                    // Erase the reference to avoid copying.
+                    assign (idx.front (), octave_value ());
 
 		    std::list<octave_value_list> next_idx (idx);
 
 		    next_idx.erase (next_idx.begin ());
 
+                    // This should be a no-op.
 		    tmp.make_unique ();
 
 		    if (! tmp.is_defined () || tmp.is_zero_by_zero ())
@@ -204,6 +203,8 @@
 		    if (! error_state)
 		      t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
 		  }
+                else
+                  error ("scalar indices required for {} in assignment.");
 	      }
 	  }
 	  break;