Commit 093942ac by Mark Wielaard Committed by Michael Koch

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
parent fd5f23d3
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> 2004-09-23 Tom Tromey <tromey@redhat.com>
PR java/17329: PR java/17329:
......
...@@ -574,14 +574,26 @@ public class Collections ...@@ -574,14 +574,26 @@ public class Collections
{ {
ListIterator itr = l.listIterator(); ListIterator itr = l.listIterator();
int i = 0; int i = 0;
Object o = itr.next(); // Assumes list is not empty (see isSequential)
boolean forward = true;
while (low <= hi) while (low <= hi)
{ {
pos = (low + hi) >> 1; pos = (low + hi) >> 1;
if (i < pos) 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 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) if (d == 0)
return pos; return pos;
else if (d < 0) else if (d < 0)
...@@ -1110,6 +1122,8 @@ public class Collections ...@@ -1110,6 +1122,8 @@ public class Collections
public static void rotate(List list, int distance) public static void rotate(List list, int distance)
{ {
int size = list.size(); int size = list.size();
if (size == 0)
return;
distance %= size; distance %= size;
if (distance == 0) if (distance == 0)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment