aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-09-23 18:01:46 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2004-09-23 18:01:46 +0000
commit093942ac675fab472ce829446c86b8233f25ee1d (patch)
treebc1195b7fcbf1306b6476efad007af02f463e4c3 /libjava
parentfd5f23d3a60e9271dd964e0d1a323e8db6f0088d (diff)
downloadgcc-093942ac675fab472ce829446c86b8233f25ee1d.zip
gcc-093942ac675fab472ce829446c86b8233f25ee1d.tar.gz
gcc-093942ac675fab472ce829446c86b8233f25ee1d.tar.bz2
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. From-SVN: r87970
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog7
-rw-r--r--libjava/java/util/Collections.java20
2 files changed, 24 insertions, 3 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index df73e81..eec4c73 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -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:
diff --git a/libjava/java/util/Collections.java b/libjava/java/util/Collections.java
index 7e5ac6e..d50563c 100644
--- a/libjava/java/util/Collections.java
+++ b/libjava/java/util/Collections.java
@@ -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;