[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: fix for binarySearch

Kaffe CVS cvs-commits at kaffe.org
Sun Sep 26 09:31:06 PDT 2004


PatchSet 5221 
Date: 2004/09/26 16:27:33
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: fix for binarySearch

2004-09-26  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/util/Collections.java:
        Resynced with GNU Classpath.

        2004-09-21  Mark Wielaard  <mark at klomp.org>

        Fixes bug #10447
        * java/util/Collections.java
        (binarySearch(List, Object, Comparator): Explicitly reverse direction
        in list iterator.

Members: 
	ChangeLog:1.2776->1.2777 
	libraries/javalib/java/util/Collections.java:1.13->1.14 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2776 kaffe/ChangeLog:1.2777
--- kaffe/ChangeLog:1.2776	Sun Sep 26 15:35:45 2004
+++ kaffe/ChangeLog	Sun Sep 26 16:27:33 2004
@@ -1,3 +1,15 @@
+2004-09-26  Dalibor Topic  <robilad at kaffe.org>
+
+	* libraries/javalib/java/util/Collections.java:
+	Resynced with GNU Classpath.
+
+	2004-09-21  Mark Wielaard  <mark at klomp.org>
+
+        Fixes bug #10447
+        * java/util/Collections.java
+        (binarySearch(List, Object, Comparator): Explicitly reverse direction
+        in list iterator.
+
 2004-09-25  Dalibor Topic  <robilad at kaffe.org>
 
 	Fix to make mauve JDK 1.4 tests run.
Index: kaffe/libraries/javalib/java/util/Collections.java
diff -u kaffe/libraries/javalib/java/util/Collections.java:1.13 kaffe/libraries/javalib/java/util/Collections.java:1.14
--- kaffe/libraries/javalib/java/util/Collections.java:1.13	Tue Sep 21 07:33:09 2004
+++ kaffe/libraries/javalib/java/util/Collections.java	Sun Sep 26 16:27:34 2004
@@ -574,14 +574,26 @@
       {
 	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)




More information about the kaffe mailing list