Mercurial > hg > octave-jordi
changeset 10772:687586b99f9d
improve struct2cell
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 08 Jul 2010 08:26:29 +0200 |
parents | 82d9efde7e96 |
children | cd16c1c3bc73 |
files | src/ChangeLog src/ov-cell.cc |
diffstat | 2 files changed, 13 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2010-07-08 Jaroslav Hajek <highegg@gmail.com> + + * ov-cell.cc (Fstruct2cell): Use octave_map. Optimize. + 2010-07-07 Rik <octave@nomad.inbox5.com> * pr-output.cc (calc_scale_exp): Avoid use of % operator on negative
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -1402,15 +1402,13 @@ if (nargin == 1) { - Octave_map m = args(0).map_value (); + const octave_map m = args(0).map_value (); if (! error_state) { - dim_vector m_dv = m.dims (); + const dim_vector m_dv = m.dims (); - string_vector keys = m.keys (); - - octave_idx_type num_fields = keys.length (); + octave_idx_type num_fields = m.nfields (); // The resulting dim_vector should have dimensions: // [numel(fields) size(struct)] @@ -1427,22 +1425,15 @@ for (int i = 1; i < result_dv.length (); i++) result_dv(i) = m_dv(i-1); - Cell c (result_dv); + NoAlias<Cell> c (result_dv); octave_idx_type n_elts = m.numel (); - for (octave_idx_type j = 0; j < num_fields; j++) - { - octave_idx_type k = j; - - const Cell vals = m.contents (keys(j)); - - for (octave_idx_type i = 0; i < n_elts; i++) - { - c(k) = vals(i); - k += num_fields; - } - } + // Fill c in one sweep. Note that thanks to octave_map structure, + // we don't need a key lookup at all. + for (octave_idx_type j = 0; j < n_elts; j++) + for (octave_idx_type i = 0; i < num_fields; i++) + c(i,j) = m.contents(i)(j); retval = c; }