From a22478ced12a9b5f2bb59aad9be4e96528a9dcbe Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Sun, 26 Sep 2004 13:14:26 -0700 Subject: [PATCH] Collections.java (sort): Copy from array in forwards order... * java/util/Collections.java (sort): Copy from array in forwards order, rather than reverse order which may be much less efficient. From-SVN: r88146 --- libjava/ChangeLog | 5 +++++ libjava/java/util/Collections.java | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 3bf4f1d1e1a..2a68a967f57 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2004-09-26 Per Bothner + + * java/util/Collections.java (sort): Copy from array in forwards + order, rather than reverse order which may be much less efficient. + 2004-09-26 Mark Wielaard * java/lang/System.java (properties): Make package private. diff --git a/libjava/java/util/Collections.java b/libjava/java/util/Collections.java index d50563c9022..d7b5e54e4a8 100644 --- a/libjava/java/util/Collections.java +++ b/libjava/java/util/Collections.java @@ -1713,11 +1713,11 @@ public class Collections { 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]); } } -- 2.30.2