aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/nio/ByteBuffer.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/nio/ByteBuffer.java')
-rw-r--r--libjava/java/nio/ByteBuffer.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java
index 276b2db..8b43da5 100644
--- a/libjava/java/nio/ByteBuffer.java
+++ b/libjava/java/nio/ByteBuffer.java
@@ -293,32 +293,27 @@ public abstract class ByteBuffer extends Buffer
*/
public int compareTo (Object obj)
{
- ByteBuffer a = (ByteBuffer) obj;
+ ByteBuffer other = (ByteBuffer) obj;
- if (a.remaining () != remaining ())
- return 1;
-
- if (! hasArray () ||
- ! a.hasArray ())
- {
- return 1;
- }
-
- int r = remaining ();
- int i1 = position ();
- int i2 = a.position ();
-
- for (int i = 0; i < r; i++)
+ int num = Math.min(remaining(), other.remaining());
+ int pos_this = position();
+ int pos_other = other.position();
+
+ for (int count = 0; count < num; count++)
{
- int t = (int) (get (i1) - a.get (i2));
-
- if (t != 0)
- {
- return (int) t;
- }
+ byte a = get(pos_this++);
+ byte b = other.get(pos_other++);
+
+ if (a == b)
+ continue;
+
+ if (a < b)
+ return -1;
+
+ return 1;
}
-
- return 0;
+
+ return remaining() - other.remaining();
}
/**