diff options
author | Sven de Marothy <sven@physto.se> | 2005-04-18 15:57:39 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2005-04-18 15:57:39 +0000 |
commit | 2d2f4282646aa1fe79e1e8780c658699b260d387 (patch) | |
tree | 93696d8906aad4829cf7c9cf885c8dfc4e9d4ed9 /java/nio | |
parent | 4a7111de174e6465fe59229623ce93fbe743a8cc (diff) | |
download | classpath-2d2f4282646aa1fe79e1e8780c658699b260d387.tar.gz |
2005-04-18 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.
Diffstat (limited to 'java/nio')
-rw-r--r-- | java/nio/ByteBufferImpl.java | 49 | ||||
-rw-r--r-- | java/nio/CharBufferImpl.java | 28 |
2 files changed, 75 insertions, 2 deletions
diff --git a/java/nio/ByteBufferImpl.java b/java/nio/ByteBufferImpl.java index 7013546f0..47961700a 100644 --- a/java/nio/ByteBufferImpl.java +++ b/java/nio/ByteBufferImpl.java @@ -149,7 +149,38 @@ final class ByteBufferImpl extends ByteBuffer return backing_buffer [(pos++) + array_offset]; } - + + /** + * Bulk get + */ + public ByteBuffer get (byte[] dst, int offset, int length) + { + checkArraySize(dst.length, offset, length); + if ( (limit - pos) < length) // check for overflow + throw new BufferUnderflowException(); + + System.arraycopy(backing_buffer, pos + array_offset, + dst, offset, length); + pos += length; + + return this; + } + + /** + * Relative bulk put(), overloads the ByteBuffer impl. + */ + public ByteBuffer put (byte[] src, int offset, int length) + { + if ( (limit - pos) < length) // check for overflow + throw new BufferOverflowException(); + checkArraySize(src.length, offset, length); + + System.arraycopy(src, offset, backing_buffer, pos + array_offset, length); + pos += length; + + return this; + } + /** * Relative put method. Writes <code>value</code> to the next position * in the buffer. @@ -207,7 +238,21 @@ final class ByteBufferImpl extends ByteBuffer public ByteBuffer putChar (char value) { - ByteBufferHelper.putChar(this, value, order()); + if (readOnly) + throw new ReadOnlyBufferException (); + if ( (limit-pos) < 2) + throw new BufferOverflowException(); + + if (endian == ByteOrder.LITTLE_ENDIAN) + { + backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF); + backing_buffer [(pos++) + array_offset] = (byte)(value>>8); + } + else + { + backing_buffer [(pos++) + array_offset] = (byte)(value>>8); + backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF); + } return this; } diff --git a/java/nio/CharBufferImpl.java b/java/nio/CharBufferImpl.java index d0087d12c..a6c81d914 100644 --- a/java/nio/CharBufferImpl.java +++ b/java/nio/CharBufferImpl.java @@ -168,6 +168,34 @@ final class CharBufferImpl extends CharBuffer } /** + * 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. * |