[multiple changes]
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. From-SVN: r98445
This commit is contained in:
parent
ce254988cf
commit
ebce970d7f
3 changed files with 113 additions and 21 deletions
|
@ -1,3 +1,21 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2005-04-20 Sven de Marothy <sven@physto.se>
|
2005-04-20 Sven de Marothy <sven@physto.se>
|
||||||
|
|
||||||
* java/text/SimpleDateFormat.java:
|
* java/text/SimpleDateFormat.java:
|
||||||
|
|
|
@ -144,13 +144,43 @@ final class ByteBufferImpl extends ByteBuffer
|
||||||
*/
|
*/
|
||||||
public byte get ()
|
public byte get ()
|
||||||
{
|
{
|
||||||
checkForUnderflow();
|
if (pos >= limit)
|
||||||
|
throw new BufferUnderflowException();
|
||||||
|
|
||||||
byte result = backing_buffer [position () + array_offset];
|
return backing_buffer [(pos++) + array_offset];
|
||||||
position (position () + 1);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Relative put method. Writes <code>value</code> to the next position
|
||||||
* in the buffer.
|
* in the buffer.
|
||||||
|
@ -161,12 +191,12 @@ final class ByteBufferImpl extends ByteBuffer
|
||||||
*/
|
*/
|
||||||
public ByteBuffer put (byte value)
|
public ByteBuffer put (byte value)
|
||||||
{
|
{
|
||||||
checkIfReadOnly();
|
if (readOnly)
|
||||||
checkForOverflow();
|
throw new ReadOnlyBufferException();
|
||||||
|
if (pos >= limit)
|
||||||
|
throw new BufferOverflowException();
|
||||||
|
|
||||||
int pos = position();
|
backing_buffer [(pos++) + array_offset] = value;
|
||||||
backing_buffer [pos + array_offset] = value;
|
|
||||||
position (pos + 1);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +238,21 @@ final class ByteBufferImpl extends ByteBuffer
|
||||||
|
|
||||||
public ByteBuffer putChar (char value)
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ final class CharBufferImpl extends CharBuffer
|
||||||
{
|
{
|
||||||
super (copy.capacity (), copy.limit (), copy.position (), 0);
|
super (copy.capacity (), copy.limit (), copy.position (), 0);
|
||||||
backing_buffer = copy.backing_buffer;
|
backing_buffer = copy.backing_buffer;
|
||||||
|
array_offset = copy.array_offset;
|
||||||
readOnly = copy.isReadOnly ();
|
readOnly = copy.isReadOnly ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +128,10 @@ final class CharBufferImpl extends CharBuffer
|
||||||
*/
|
*/
|
||||||
public char get ()
|
public char get ()
|
||||||
{
|
{
|
||||||
checkForUnderflow();
|
if (pos >= limit)
|
||||||
|
throw new BufferUnderflowException();
|
||||||
|
|
||||||
char result = backing_buffer [position ()];
|
return backing_buffer [(pos++) + array_offset];
|
||||||
position (position () + 1);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,10 +142,12 @@ final class CharBufferImpl extends CharBuffer
|
||||||
*/
|
*/
|
||||||
public CharBuffer put (char value)
|
public CharBuffer put (char value)
|
||||||
{
|
{
|
||||||
checkIfReadOnly();
|
if (readOnly)
|
||||||
|
throw new ReadOnlyBufferException();
|
||||||
backing_buffer [position ()] = value;
|
if (pos >= limit)
|
||||||
position (position () + 1);
|
throw new BufferOverflowException();
|
||||||
|
|
||||||
|
backing_buffer [(pos++) + array_offset] = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,9 +164,37 @@ final class CharBufferImpl extends CharBuffer
|
||||||
{
|
{
|
||||||
checkIndex(index);
|
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
|
* Absolute put method. Writes <code>value</code> to position
|
||||||
* <code>index</code> in the buffer.
|
* <code>index</code> in the buffer.
|
||||||
|
@ -178,7 +208,7 @@ final class CharBufferImpl extends CharBuffer
|
||||||
checkIndex(index);
|
checkIndex(index);
|
||||||
checkIfReadOnly();
|
checkIfReadOnly();
|
||||||
|
|
||||||
backing_buffer [index] = value;
|
backing_buffer [index + array_offset] = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue