Following up Jeroen's patch, here are a few more optimizations I'd
already done to a few of the NIO buffer classes.
This improves the nio charset converter performance noticably.


/Sven

2005-04-18  Sven de Marothy  <[EMAIL PROTECTED]>

        * 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.

Index: java/nio/ByteBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ByteBufferImpl.java,v
retrieving revision 1.11
diff -u -r1.11 ByteBufferImpl.java
--- java/nio/ByteBufferImpl.java	18 Apr 2005 09:03:04 -0000	1.11
+++ java/nio/ByteBufferImpl.java	18 Apr 2005 15:55:41 -0000
@@ -149,7 +149,38 @@
 
     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 @@
   
   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;
   }
   
Index: java/nio/CharBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharBufferImpl.java,v
retrieving revision 1.8
diff -u -r1.8 CharBufferImpl.java
--- java/nio/CharBufferImpl.java	18 Apr 2005 09:03:04 -0000	1.8
+++ java/nio/CharBufferImpl.java	18 Apr 2005 15:55:41 -0000
@@ -168,6 +168,34 @@
   }
   
   /**
+   * 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.
    *
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to