diff options
author | Per Bothner <per@bothner.com> | 2004-02-08 13:02:53 -0800 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2004-02-08 13:02:53 -0800 |
commit | 40c23042f4594368c96e1af7dc65b72590d584b0 (patch) | |
tree | a1e145e7726c0c5b674ef91a6ecd841daaa826ef /libjava/java/nio/LongViewBufferImpl.java | |
parent | b46b8fb40cf29c5f724d87f6022c6c8242e50bf2 (diff) | |
download | gcc-40c23042f4594368c96e1af7dc65b72590d584b0.zip gcc-40c23042f4594368c96e1af7dc65b72590d584b0.tar.gz gcc-40c23042f4594368c96e1af7dc65b72590d584b0.tar.bz2 |
ByteBuffer.java (shiftDown): New helper method.
* java/nio/ByteBuffer.java (shiftDown): New helper method.
* java/nio/natDirectByteBufferImpl.cc (shiftDown): New implementation.
* java/nio/ByteBufferImpl.java (compact): Use new shiftDown method.
* sava/nio/ByteBufferHelper.java: Remove redundant 'final' specifiers.
Pass ByteOrder parameter to most methods, since the underlying
ByteBuffer's order isn't always what we should use.
* java/nio/ByteBufferImpl.java: Pass byte-order various places.
* java/nio/DirectByteBufferImpl.java: Likewise.
Use ByteBufferHelper methods.
* java/nio/MappedByteBufferImpl.java: Likewise.
(compact): Use shiftDown.
* java/nio/CharViewBufferImpl.java (<init>): Pass byte-order.
(get, put): Use ByteBufferHelper.
(compact): Use new shiftDown method.
(duplicate(boolean)): New helper method.
(duplicate, asReadOnlyBuffer): Use it.
(order): Return endian field.
* java/nio/DoubleViewBufferImpl.java: Likewise.
* java/nio/FloatViewBufferImpl.java: Likewise.
* java/nio/IntViewBufferImpl.java: Likewise.
* java/nio/LongViewBufferImpl.java: Likewise.
* java/nio/ShortViewBufferImpl.java: Likewise.
* java/nio/CharViewBufferImpl.java (subsequence): Redundant test.
* java/nio/DirectByteBufferImpl.java (shiftDown): New native method.
(compact): Re-implement using shiftDown.
From-SVN: r77501
Diffstat (limited to 'libjava/java/nio/LongViewBufferImpl.java')
-rw-r--r-- | libjava/java/nio/LongViewBufferImpl.java | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/libjava/java/nio/LongViewBufferImpl.java b/libjava/java/nio/LongViewBufferImpl.java index c7ada48..a405ec8 100644 --- a/libjava/java/nio/LongViewBufferImpl.java +++ b/libjava/java/nio/LongViewBufferImpl.java @@ -1,5 +1,5 @@ /* LongViewBufferImpl.java -- - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,54 +40,47 @@ package java.nio; class LongViewBufferImpl extends LongBuffer { - private boolean readOnly; + /** Position in bb (i.e. a byte offset) where this buffer starts. */ private int offset; private ByteBuffer bb; + private boolean readOnly; private ByteOrder endian; - public LongViewBufferImpl (ByteBuffer bb, boolean readOnly) - { - super (bb.remaining () >> 3, bb.remaining () >> 3, bb.position (), 0); - this.bb = bb; - this.readOnly = readOnly; - // FIXME: What if this is called from LongByteBufferImpl and ByteBuffer has changed its endianess ? - this.endian = bb.order (); - } - public LongViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly) + int limit, int position, int mark, + boolean readOnly, ByteOrder endian) { super (limit >> 3, limit >> 3, position >> 3, mark >> 3); this.bb = bb; this.offset = offset; this.readOnly = readOnly; - // FIXME: What if this is called from LongViewBufferImpl and ByteBuffer has changed its endianess ? - this.endian = bb.order (); + this.endian = endian; } public long get () { - long result = bb.getLong ((position () << 3) + offset); - position (position () + 1); + int p = position(); + long result = ByteBufferHelper.getLong(bb, (p << 3) + offset, endian); + position(p + 1); return result; } public long get (int index) { - return bb.getLong ((index << 3) + offset); + return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian); } public LongBuffer put (long value) { - bb.putLong ((position () << 3) + offset, value); - position (position () + 1); + int p = position(); + ByteBufferHelper.putLong(bb, (p << 3) + offset, value, endian); + position(p + 1); return this; } public LongBuffer put (int index, long value) { - bb.putLong ((index << 3) + offset, value); + ByteBufferHelper.putLong(bb, (index << 3) + offset, value, endian); return this; } @@ -95,48 +88,42 @@ class LongViewBufferImpl extends LongBuffer { if (position () > 0) { - // Copy all data from position() to limit() to the beginning of the - // buffer, set position to end of data and limit to capacity - // XXX: This can surely be optimized, for direct and non-direct buffers - int count = limit () - position (); - - for (int i = 0; i < count; i++) - { - bb.putLong ((i >> 3) + offset, - bb.getLong (((i + position ()) >> 3) + offset)); - } - + bb.shiftDown(offset, offset + 8 * position(), 8 * count); position (count); limit (capacity ()); } - return this; } - public LongBuffer duplicate () - { - // Create a copy of this object that shares its content - // FIXME: mark is not correct - return new LongViewBufferImpl (bb, offset, capacity (), limit (), - position (), -1, isReadOnly ()); - } - public LongBuffer slice () { // Create a sliced copy of this object that shares its content. return new LongViewBufferImpl (bb, (position () >> 3) + offset, - remaining (), remaining (), 0, -1, - isReadOnly ()); + remaining(), remaining(), 0, -1, + readOnly, endian); } - public LongBuffer asReadOnlyBuffer () + LongBuffer duplicate (boolean readOnly) { - // Create a copy of this object that shares its content and is read-only - return new LongViewBufferImpl (bb, (position () >> 3) + offset, - remaining (), remaining (), 0, -1, true); + int pos = position(); + reset(); + int mark = position(); + position(pos); + return new LongViewBufferImpl (bb, offset, capacity(), limit(), + pos, mark, readOnly, endian); } + public LongBuffer duplicate () + { + return duplicate(readOnly); + } + + public LongBuffer asReadOnlyBuffer () + { + return duplicate(true); + } + public boolean isReadOnly () { return readOnly; @@ -149,6 +136,6 @@ class LongViewBufferImpl extends LongBuffer public ByteOrder order () { - return ByteOrder.LITTLE_ENDIAN; + return endian; } } |