Mercurial > hg > octave-nkf
changeset 9127:5ec4dc52c131
fix empty struct indexed assignment
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 17 Apr 2009 11:07:00 +0200 |
parents | 5780b3b80425 |
children | c71fe7045aa0 |
files | src/ChangeLog src/oct-map.cc |
diffstat | 2 files changed, 14 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2009-04-17 Jaroslav Hajek <highegg@gmail.com> + + * oct-map.cc (Octave_map::assign (const octave_value_list&, const + std::string&, const Cell&)): Fix & simplify. + (common_size): Remove. + 2009-04-16 Jaroslav Hajek <highegg@gmail.com> * pt-idx.cc (make_value_list): Gripe on magic end query for undefined
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -345,36 +345,6 @@ return *this; } -static dim_vector -common_size (const dim_vector& a, const dim_vector& b) -{ - dim_vector retval; - - octave_idx_type a_len = a.length (); - octave_idx_type b_len = b.length (); - - octave_idx_type new_len = std::max (a_len, b_len); - octave_idx_type min_len = std::min (a_len, b_len); - - retval.resize (new_len); - - for (octave_idx_type i = 0; i < min_len; i++) - retval(i) = std::max (a(i), b(i)); - - if (a_len < b_len) - { - for (octave_idx_type i = min_len; i < b_len; i++) - retval(i) = b(i); - } - else if (a_len > b_len) - { - for (octave_idx_type i = min_len; i < a_len; i++) - retval(i) = a(i); - } - - return retval; -} - Octave_map& Octave_map::assign (const octave_value_list& idx, const std::string& k, const Cell& rhs) @@ -383,32 +353,23 @@ if (contains (k)) tmp = map[k]; + else + tmp = Cell (dimensions); - octave_value fill_value = Matrix (); - - tmp.assign (idx, rhs, fill_value); + tmp.assign (idx, rhs); if (! error_state) { - dim_vector rhs_dims = tmp.dims (); - - dim_vector curr_dims = dims (); - - dim_vector new_dims = common_size (rhs_dims, curr_dims); + dim_vector tmp_dims = tmp.dims (); - if (new_dims != rhs_dims) - { - tmp.resize (new_dims, fill_value); - } - - if (new_dims != curr_dims) + if (tmp_dims != dimensions) { for (iterator p = begin (); p != end (); p++) - contents(p).resize (new_dims, fill_value); + contents(p).resize (tmp_dims, Cell::resize_fill_value ()); + + dimensions = tmp_dims; } - dimensions = new_dims; - maybe_add_to_key_list (k); map[k] = tmp;