# HG changeset patch # User Jaroslav Hajek # Date 1231449137 -3600 # Node ID 7b25349b32e6debab897aca7a1aa259d6b1f248d # Parent dd52e541418b6ad9d788c0710bdf12727f06f1ab avoid redundant copying in {} assignment diff -r dd52e541418b -r 7b25349b32e6 src/ChangeLog --- a/src/ChangeLog Mon Jan 05 21:33:54 2009 -0500 +++ b/src/ChangeLog Thu Jan 08 22:12:17 2009 +0100 @@ -1,3 +1,8 @@ +2009-01-08 Jaroslav Hajek + + * ov-cell.cc (octave_cell::subsasgn): Erase duplicate lhs value + prior to assignment to avoid a redundant copy. + 2008-12-26 Thorsten Meyer * mappers.cc (Ftoascii), mappers.cc (Ftolower), mappers.cc diff -r dd52e541418b -r 7b25349b32e6 src/ov-cell.cc --- 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 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;