2004-09-23 Mark Wielaard <mark@klomp.org>
authorMark Wielaard <mark@klomp.org>
Thu, 23 Sep 2004 18:01:46 +0000 (18:01 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Thu, 23 Sep 2004 18:01:46 +0000 (18:01 +0000)
* java/util/Collections.java
(binarySearch(List, Object, Comparator)): Explicitly
reverse direction in list iterator.
(rotate): Just return when list is empty.

From-SVN: r87970

libjava/ChangeLog
libjava/java/util/Collections.java

index df73e81bbb4c00e0733f826ec6970a60feeeba0e..eec4c73d3bb4edeecb224745d17e0d20db4c955a 100644 (file)
@@ -1,3 +1,10 @@
+2004-09-23  Mark Wielaard  <mark@klomp.org>
+
+       * java/util/Collections.java
+       (binarySearch(List, Object, Comparator)): Explicitly
+       reverse direction in list iterator.
+       (rotate): Just return when list is empty.
+
 2004-09-23  Tom Tromey  <tromey@redhat.com>
 
        PR java/17329:
index 7e5ac6ec2c119dd0f5ce80c1b79a4b83f29e066f..d50563c9022383d667d019251d4a86786dc12ee4 100644 (file)
@@ -574,14 +574,26 @@ public class Collections
       {
        ListIterator itr = l.listIterator();
         int i = 0;
+       Object o = itr.next(); // Assumes list is not empty (see isSequential)
+       boolean forward = true;
         while (low <= hi)
           {
             pos = (low + hi) >> 1;
             if (i < pos)
-              for ( ; i != pos; i++, itr.next());
+             {
+               if (!forward)
+                 itr.next(); // Changing direction first.
+               for ( ; i != pos; i++, o = itr.next());
+               forward = true;
+             }
             else
-              for ( ; i != pos; i--, itr.previous());
-           final int d = compare(key, itr.next(), c);
+             {
+               if (forward)
+                 itr.previous(); // Changing direction first.
+               for ( ; i != pos; i--, o = itr.previous());
+               forward = false;
+             }
+           final int d = compare(key, o, c);
            if (d == 0)
               return pos;
            else if (d < 0)
@@ -1110,6 +1122,8 @@ public class Collections
   public static void rotate(List list, int distance)
   {
     int size = list.size();
+    if (size == 0)
+      return;
     distance %= size;
     if (distance == 0)
       return;