# HG changeset patch # User Jaroslav Hajek # Date 1245654043 -7200 # Node ID d3b6e85aaf53ccf2db3b6e3ee9436982ec2caa13 # Parent ff8c445edeb4b9ecdd861de5ed339e4efde5ebc0 fix slow cellstr -> char matrix conversions diff -r ff8c445edeb4 -r d3b6e85aaf53 liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Jun 22 07:56:24 2009 +0200 +++ b/liboctave/ChangeLog Mon Jun 22 09:00:43 2009 +0200 @@ -1,3 +1,8 @@ +2009-06-22 Jaroslav Hajek + + * chMatrix.cc (charMatrix::charMatrix (const string_vector&)): + Optimize w.r.t. COW of std::string. + 2009-06-18 Jaroslav Hajek * dMatrix.cc (xgemm): Replace resize() with uninitialized allocations diff -r ff8c445edeb4 -r d3b6e85aaf53 liboctave/chMatrix.cc --- a/liboctave/chMatrix.cc Mon Jun 22 07:56:24 2009 +0200 +++ b/liboctave/chMatrix.cc Mon Jun 22 09:00:43 2009 +0200 @@ -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]; } } diff -r ff8c445edeb4 -r d3b6e85aaf53 src/ChangeLog --- a/src/ChangeLog Mon Jun 22 07:56:24 2009 +0200 +++ b/src/ChangeLog Mon Jun 22 09:00:43 2009 +0200 @@ -1,3 +1,7 @@ +2009-06-22 Jaroslav Hajek + + * ov-cell.cc (octave_cell::all_strings): Avoid duplicate conversions. + 2009-06-20 Jaroslav Hajek * ov.cc (Fsubsasgn): Uniquify shared value before assigning to it. diff -r ff8c445edeb4 -r d3b6e85aaf53 src/ov-cell.cc --- a/src/ov-cell.cc Mon Jun 22 07:56:24 2009 +0200 +++ b/src/ov-cell.cc Mon Jun 22 09:00:43 2009 +0200 @@ -29,6 +29,7 @@ #include #include #include +#include #include "Array-util.h" #include "byte-swap.h" @@ -572,6 +573,8 @@ octave_idx_type max_len = 0; + std::queue 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 ();