diff options
author | Michael Koch <konqueror@gmx.de> | 2004-04-29 18:04:45 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2004-04-29 18:04:45 +0000 |
commit | b935cf8baca8ebbca092b373261ebe8736108c8c (patch) | |
tree | 0f9666f8fd4a95b2c2d3945dcaf237d1713615cf /java/nio/ByteBuffer.java | |
parent | d2614427e5dff01396e5b1ddf9581e78d51580a8 (diff) | |
download | classpath-b935cf8baca8ebbca092b373261ebe8736108c8c.tar.gz |
2004-04-29 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBuffer.java,
java/nio/CharBuffer.java,
java/nio/DoubleBuffer.java,
java/nio/FloatBuffer.java,
java/nio/IntBuffer.java,
java/nio/LongBuffer.java,
java/nio/ShortBuffer.java:
(compareTo): Fixed bogus implementation in all buffer classes.
Diffstat (limited to 'java/nio/ByteBuffer.java')
-rw-r--r-- | java/nio/ByteBuffer.java | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/java/nio/ByteBuffer.java b/java/nio/ByteBuffer.java index 276b2dbcb..8b43da579 100644 --- a/java/nio/ByteBuffer.java +++ b/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(); } /** |