Mercurial > hg > octave-lyh
changeset 9370:4ff6f8efdda2
fix slow cellstr -> char matrix conversions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 22 Jun 2009 08:59:38 +0200 |
parents | 14dca190857f |
children | 56751dfc6ebd |
files | liboctave/ChangeLog liboctave/chMatrix.cc src/ChangeLog src/ov-cell.cc |
diffstat | 4 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2009-06-22 Jaroslav Hajek <highegg@gmail.com> + + * chMatrix.cc (charMatrix::charMatrix (const string_vector&)): + Optimize w.r.t. COW of std::string. + 2009-06-18 Jaroslav Hajek <highegg@gmail.com> * oct-sort.cc (lookup_impl<T, Comp>): New helper inline function.
--- a/liboctave/chMatrix.cc +++ b/liboctave/chMatrix.cc @@ -81,9 +81,10 @@ for (octave_idx_type i = 0; i < nr; i++) { - octave_idx_type nc = s[i].length (); + const std::string si = s(i); + octave_idx_type nc = si.length (); for (octave_idx_type j = 0; j < nc; j++) - elem (i, j) = s[i][j]; + elem (i, j) = si[j]; } }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2009-06-22 Jaroslav Hajek <highegg@gmail.com> + + * ov-cell.cc (octave_cell::all_strings): Avoid duplicate conversions. + 2009-06-20 Jaroslav Hajek <highegg@gmail.com> * ov.cc (Fsubsasgn): Uniquify shared value before assigning to it.
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -29,6 +29,7 @@ #include <iostream> #include <sstream> #include <vector> +#include <queue> #include "Array-util.h" #include "byte-swap.h" @@ -572,6 +573,8 @@ octave_idx_type max_len = 0; + std::queue<string_vector> strvec_queue; + for (octave_idx_type i = 0; i < nel; i++) { string_vector s = matrix(i).all_strings (); @@ -587,15 +590,18 @@ if (s_max_len > max_len) max_len = s_max_len; + + strvec_queue.push (s); } - retval.resize (n_elts); + retval = string_vector (n_elts); octave_idx_type k = 0; for (octave_idx_type i = 0; i < nel; i++) { - string_vector s = matrix(i).all_strings (); + const string_vector s = strvec_queue.front (); + strvec_queue.pop (); octave_idx_type s_len = s.length ();