summaryrefslogtreecommitdiff
path: root/libjava/java/nio/CharBufferImpl.java
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-20 06:05:04 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-20 06:05:04 +0000
commit3a3b655bdfd8b1655b2fb03ce4d742117a96705e (patch)
tree299c11c27a0bdee12676f0fa833c032c9a885cc7 /libjava/java/nio/CharBufferImpl.java
parentb1fef53a94dcbf468b2280fe532ca431c9b2c72e (diff)
downloadgcc-3a3b655bdfd8b1655b2fb03ce4d742117a96705e.tar.gz
2005-04-20 Sven de Marothy <sven@physto.se>
* java/nio/ByteBufferImpl.java: (putChar): Inlined for speed. (put, get): Bulk methods can use arraycopy. * java/nio/CharBufferImpl.java: (put, get): Bulk methods can use arraycopy. 2005-04-20 Jeroen Frijters <jeroen@frijters.net> * java/nio/ByteBufferImpl.java (get(), put(byte)): Inlined checks and field updates. * java/nio/CharBufferImpl.java (CharBufferImpl(CharBufferImpl)): Copy array_offset field. (get(), put(char)): Inlined checks and field updates. Fixed to take array_offset into account. (get(int), put(int, char)): Fixed to take array_offset into account. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98445 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/nio/CharBufferImpl.java')
-rw-r--r--libjava/java/nio/CharBufferImpl.java50
1 files changed, 40 insertions, 10 deletions
diff --git a/libjava/java/nio/CharBufferImpl.java b/libjava/java/nio/CharBufferImpl.java
index f9babe8287b..a6c81d914fa 100644
--- a/libjava/java/nio/CharBufferImpl.java
+++ b/libjava/java/nio/CharBufferImpl.java
@@ -62,6 +62,7 @@ final class CharBufferImpl extends CharBuffer
{
super (copy.capacity (), copy.limit (), copy.position (), 0);
backing_buffer = copy.backing_buffer;
+ array_offset = copy.array_offset;
readOnly = copy.isReadOnly ();
}
@@ -127,11 +128,10 @@ final class CharBufferImpl extends CharBuffer
*/
public char get ()
{
- checkForUnderflow();
+ if (pos >= limit)
+ throw new BufferUnderflowException();
- char result = backing_buffer [position ()];
- position (position () + 1);
- return result;
+ return backing_buffer [(pos++) + array_offset];
}
/**
@@ -142,10 +142,12 @@ final class CharBufferImpl extends CharBuffer
*/
public CharBuffer put (char value)
{
- checkIfReadOnly();
-
- backing_buffer [position ()] = value;
- position (position () + 1);
+ if (readOnly)
+ throw new ReadOnlyBufferException();
+ if (pos >= limit)
+ throw new BufferOverflowException();
+
+ backing_buffer [(pos++) + array_offset] = value;
return this;
}
@@ -162,10 +164,38 @@ final class CharBufferImpl extends CharBuffer
{
checkIndex(index);
- return backing_buffer [index];
+ return backing_buffer [index + array_offset];
}
/**
+ * Bulk get, overloaded for speed.
+ */
+ public CharBuffer get (char[] dst, int offset, int length)
+ {
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
+ System.arraycopy(backing_buffer, pos + array_offset,
+ dst, offset, length);
+ pos += length;
+ return this;
+ }
+
+ /**
+ * Bulk put, overloaded for speed.
+ */
+ public CharBuffer put (char[] src, int offset, int length)
+ {
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
+ System.arraycopy(src, offset,
+ backing_buffer, pos + array_offset, length);
+ pos += length;
+ return this;
+ }
+
+ /**
* Absolute put method. Writes <code>value</code> to position
* <code>index</code> in the buffer.
*
@@ -178,7 +208,7 @@ final class CharBufferImpl extends CharBuffer
checkIndex(index);
checkIfReadOnly();
- backing_buffer [index] = value;
+ backing_buffer [index + array_offset] = value;
return this;
}