This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH to Collections.sort


Checked into mainline.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

2004-09-26  Per Bothner  <per@bothner.com>

	* java/util/Collections.java (sort):  Copy from array in forwards
	order, rather than reverse order which may be much less efficient.

Index: java/util/Collections.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Collections.java,v
retrieving revision 1.11
diff -u -r1.11 Collections.java
--- java/util/Collections.java	23 Sep 2004 18:01:46 -0000	1.11
+++ java/util/Collections.java	25 Sep 2004 19:04:58 -0000
@@ -1713,11 +1713,11 @@
   {
     Object[] a = l.toArray();
     Arrays.sort(a, c);
-    ListIterator i = l.listIterator(a.length);
-    for (int pos = a.length; --pos >= 0; )
+    ListIterator i = l.listIterator();
+    for (int pos = 0, alen = a.length;  pos < alen;  pos++)
       {
-	i.previous();
-	i.set(a[pos]);
+        i.next();
+        i.set(a[pos]);
       }
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]