Mercurial > hg > octave-lyh
changeset 8682:38968f09f7ca
optimize Octave_map::index
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 05 Feb 2009 15:15:59 +0100 |
parents | 72b1f1eece70 |
children | e4f89f4a7cf8 |
files | src/ChangeLog src/oct-map.cc |
diffstat | 2 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2009-02-05 Jaroslav Hajek <highegg@gmail.com> + + * oct-map.cc (Octave_map::index): Optimize. + 2009-02-05 Jaroslav Hajek <highegg@gmail.com> * OPERATORS/op-cm-cs.cc: Use scalar_value in scalar-to-matrix
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -475,23 +475,34 @@ Octave_map::index (const octave_value_list& idx, bool resize_ok) const { Octave_map retval; - - if (idx.length () > 0) + octave_idx_type n_idx = idx.length (); + if (n_idx > 0) { - for (const_iterator p = begin (); p != end (); p++) - { - // FIXME: this is sub-optimal: idx is converted multiple times. - // Need to convert here and use ArrayN<octave_value>::index. - Cell tmp = contents(p).index (idx, resize_ok); + Array<idx_vector> ra_idx (n_idx); + for (octave_idx_type i = 0; i < n_idx; i++) + { + ra_idx(i) = idx(i).index_vector (); + if (error_state) + break; + } - if (error_state) - break; + if (! error_state) + { + for (const_iterator p = begin (); p != end (); p++) + { + + Cell tmp = contents (p); + tmp = tmp.ArrayN<octave_value>::index (ra_idx, resize_ok); - retval.assign (key(p), tmp); - } + if (error_state) + break; - // Preserve order of keys. - retval.key_list = key_list; + retval.assign (key(p), tmp); + } + + // Preserve order of keys. + retval.key_list = key_list; + } } else retval = *this;