This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: Arrays patch
- From: Tom Tromey <tromey at redhat dot com>
- To: GCJ-patches <java-patches at gcc dot gnu dot org>
- Date: 23 Jan 2007 13:57:12 -0700
- Subject: Patch: FYI: Arrays patch
- Reply-to: tromey at redhat dot com
I'm checking this in on the 4.2 branch, the trunk, and the RH 4.1
merge branch.
This patch was a bit controversial when proposed for Classpath.
Please track the discussion there.
Tom
Index: ChangeLog
from Marco Trudel <mtrudel@gmx.ch>
* java/util/Arrays.java (binarySearch): Change comparison order.
Index: java/util/Arrays.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Arrays.java,v
retrieving revision 1.34
diff -u -r1.34 Arrays.java
--- java/util/Arrays.java 8 Jan 2007 17:55:34 -0000 1.34
+++ java/util/Arrays.java 20 Jan 2007 02:01:37 -0000
@@ -1,5 +1,5 @@
/* Arrays.java -- Utility class with methods to operate on arrays
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -639,10 +639,13 @@
while (low <= hi)
{
mid = (low + hi) >>> 1;
- final int d = Collections.compare(key, a[mid], c);
+ // NOTE: Please keep the order of a[mid] and key. Although
+ // not required by the specs, the RI has it in this order as
+ // well, and real programs (erroneously) depend on it.
+ final int d = Collections.compare(a[mid], key, c);
if (d == 0)
return mid;
- else if (d < 0)
+ else if (d > 0)
hi = mid - 1;
else
// This gets the insertion point right on the last loop