changeset 8663:4238f2600a17

fix string_vector::sort
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 04 Feb 2009 16:05:01 +0100
parents af72c8137d64
children e07e93c04080
files liboctave/Array-str.cc liboctave/ChangeLog liboctave/str-vec.cc liboctave/str-vec.h
diffstat 4 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array-str.cc	Wed Feb 04 13:53:57 2009 +0100
+++ b/liboctave/Array-str.cc	Wed Feb 04 16:05:01 2009 +0100
@@ -24,14 +24,14 @@
 #include <config.h>
 #endif
 
+#include <string>
+
 // Instantiate Arrays of strings.
 
 #include "Array.h"
 #include "Array.cc"
 #include "oct-sort.cc"
 
-#include <string>
-
 INSTANTIATE_ARRAY_SORT (std::string);
 
 INSTANTIATE_ARRAY (std::string, OCTAVE_API);
--- a/liboctave/ChangeLog	Wed Feb 04 13:53:57 2009 +0100
+++ b/liboctave/ChangeLog	Wed Feb 04 16:05:01 2009 +0100
@@ -1,3 +1,9 @@
+2009-02-04  Jaroslav Hajek  <highegg@gmail.com>
+
+	* str-vec.h (string_vector::sort): Remove implementation.
+	* str-vec.cc (string_vector::sort): Move here. Use in-place sorting.
+	* Array-str.cc: Fix order of header files.
+
 2009-02-04  Jaroslav Hajek  <highegg@gmail.com>
 
 	* oct-locbuf.h: Specialize OCTAVE_LOCAL_BUFFER to use chunked
--- a/liboctave/str-vec.cc	Wed Feb 04 13:53:57 2009 +0100
+++ b/liboctave/str-vec.cc	Wed Feb 04 16:05:01 2009 +0100
@@ -84,6 +84,18 @@
 }
 
 string_vector&
+string_vector::sort (bool make_uniq)
+{
+  // Don't use Array<std::string>::sort () to allow sorting in place.
+  octave_sort<std::string> lsort;
+  lsort.sort (Array<std::string>::fortran_vec (), length ());
+
+  if (make_uniq)
+    uniq ();
+
+  return *this;
+}
+string_vector&
 string_vector::uniq (void)
 {
   octave_idx_type len = length ();
--- a/liboctave/str-vec.h	Wed Feb 04 13:53:57 2009 +0100
+++ b/liboctave/str-vec.h	Wed Feb 04 16:05:01 2009 +0100
@@ -84,15 +84,7 @@
 
   std::string operator[] (octave_idx_type i) const { return Array<std::string>::elem (i); }
 
-  string_vector& sort (bool make_uniq = false)
-  {
-    Array<std::string>::sort ();
-
-    if (make_uniq)
-      uniq ();
-
-    return *this;
-  }
+  string_vector& sort (bool make_uniq = false);
 
   string_vector& uniq (void);