Mercurial > hg > octave-lyh
changeset 8446:7b25349b32e6
avoid redundant copying in {} assignment
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 08 Jan 2009 22:12:17 +0100 |
parents | dd52e541418b |
children | adab48231a03 |
files | src/ChangeLog src/ov-cell.cc |
diffstat | 2 files changed, 13 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-01-08 Jaroslav Hajek <highegg@gmail.com> + + * ov-cell.cc (octave_cell::subsasgn): Erase duplicate lhs value + prior to assignment to avoid a redundant copy. + 2008-12-26 Thorsten Meyer <thorsten.meyier@gmx.de> * mappers.cc (Ftoascii), mappers.cc (Ftolower), mappers.cc
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -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;