diff liboctave/oct-sort.cc @ 11938:3b5a99b63570 release-3-0-x

backport sorting fixes
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 24 Feb 2009 07:53:24 +0100
parents d11919389e09
children
line wrap: on
line diff
--- a/liboctave/oct-sort.cc	Tue Feb 24 07:48:33 2009 +0100
+++ b/liboctave/oct-sort.cc	Tue Feb 24 07:53:24 2009 +0100
@@ -29,8 +29,9 @@
   replacing PyObject* with the type of the class T.
 
 * replaced usages of malloc, free, memcpy and memmove by standard C++
-  new [], delete [] and std::copy. Note that replacing memmove by std::copy
-  is possible if the destination starts before the source.
+  new [], delete [] and std::copy and std::copy_backward. Note that replacing
+  memmove by std::copy is possible if the destination starts before the source.
+  If not, std::copy_backward needs to be used.
   
 
 The Python license is
@@ -731,7 +732,7 @@
 	    {
 	      dest -= k;
 	      pa -= k;
-              std::copy (pa+1, pa+1 + k, dest+1);
+              std::copy_backward (pa+1, pa+1 + k, dest+1 + k);
 	      na -= k;
 	      if (na == 0)
 		goto Succeed;
@@ -782,7 +783,7 @@
   /* The first element of pb belongs at the front of the merge. */
   dest -= na;
   pa -= na;
-  std::copy (pa+1, pa+1 + na, dest+1);
+  std::copy_backward (pa+1, pa+1 + na, dest+1 + na);
   *dest = *pb;
 
   return 0;