diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-04 21:31:30 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-04 21:31:30 +0000 |
commit | a221385cec60e1ba526d292898aeb99953891407 (patch) | |
tree | 7281d10d42a1f2c51d91d3923158d74d7a9511ff /libjava/java/nio/ShortBuffer.java | |
parent | a6645eaed032b9d5277b199e005974b5dab19c0e (diff) | |
download | ppe42-gcc-a221385cec60e1ba526d292898aeb99953891407.tar.gz ppe42-gcc-a221385cec60e1ba526d292898aeb99953891407.zip |
2004-05-04 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81489 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/nio/ShortBuffer.java')
-rw-r--r-- | libjava/java/nio/ShortBuffer.java | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/libjava/java/nio/ShortBuffer.java b/libjava/java/nio/ShortBuffer.java index 61097d04dd9..9f542769fac 100644 --- a/libjava/java/nio/ShortBuffer.java +++ b/libjava/java/nio/ShortBuffer.java @@ -1,5 +1,5 @@ /* ShortBuffer.java -- - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -265,32 +265,27 @@ public abstract class ShortBuffer extends Buffer */ public int compareTo (Object obj) { - ShortBuffer a = (ShortBuffer) obj; + ShortBuffer other = (ShortBuffer) 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; - } + short a = get(pos_this++); + short b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** |