Mercurial > octave-nkf
diff src/ov-struct.cc @ 9522:e79470be3ecb
implement subsasgn this-arg optimization
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 13 Aug 2009 15:51:57 +0200 |
parents | 610bf90fce2a |
children | 8e5009334661 |
line wrap: on
line diff
--- a/src/ov-struct.cc Thu Aug 13 11:52:07 2009 +0200 +++ b/src/ov-struct.cc Thu Aug 13 15:51:57 2009 +0200 @@ -93,8 +93,8 @@ error ("%s cannot be indexed with %c", nm.c_str (), t); } -static void -gripe_failed_assignment (void) +void +octave_struct::gripe_failed_assignment (void) { error ("assignment to structure element failed"); } @@ -254,6 +254,43 @@ } octave_value +octave_struct::dotasgn (const octave_value_list& idx, const octave_value& rhs) +{ + octave_value retval; + + assert (idx.length () == 1); + + std::string key = idx(0).string_value (); + + if (rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (rhs.list_value ()); + + // The shape of the RHS is irrelevant, we just want + // the number of elements to agree and to preserve the + // shape of the left hand side of the assignment. + + if (numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (dims ()); + + map.assign (key, tmp_cell); + } + else + // Regularize a null matrix if stored into a struct component. + map.assign (key, rhs.storable_value ()); + + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + + return retval; +} + +octave_value octave_struct::subsasgn (const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs) @@ -456,7 +493,8 @@ } else { - if (t_rhs.is_map()) + if (t_rhs.is_map() + || (is_object () && t_rhs.is_object ())) { Octave_map rhs_map = t_rhs.map_value (); @@ -498,36 +536,7 @@ case '.': { - octave_value_list key_idx = idx.front (); - - assert (key_idx.length () == 1); - - std::string key = key_idx(0).string_value (); - - if (t_rhs.is_cs_list ()) - { - Cell tmp_cell = Cell (t_rhs.list_value ()); - - // The shape of the RHS is irrelevant, we just want - // the number of elements to agree and to preserve the - // shape of the left hand side of the assignment. - - if (numel () == tmp_cell.numel ()) - tmp_cell = tmp_cell.reshape (dims ()); - - map.assign (key, tmp_cell); - } - else - // Regularize a null matrix if stored into a struct component. - map.assign (key, t_rhs.storable_value ()); - - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); + retval = dotasgn (idx.front (), t_rhs); } break;