classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Speed up java.nio.ByteBuffer


From: Florian Weimer
Subject: [cp-patches] Speed up java.nio.ByteBuffer
Date: Thu, 12 Aug 2004 19:32:37 +0200

On GCJ, this patch results in a 18% improvement in speed for loading
databases with Berkeley DB Java Edition.  Regression-tested (modulo
changes in comments) with GCJ and a DbLoad/DbDump with JE.

Further improvements will require a new class for a read-only byte
buffer, so that the read-only flag can go.  Where should I put this
one?

What are the necessary steps to get the patches installed?  Should I
install them in the GCC repository first?

2004-08-12  Florian Weimer  <address@hidden>

        * java/nio/ByteBufferImpl.java (put): New methods to speed up
        ByteBuffer put and array put operations.
        

--- /home/fw/src/gnu/classpath/java/nio/ByteBufferImpl.java     2004-06-16 
10:57:10.000000000 +0200
+++ ByteBufferImpl.java 2004-08-12 19:19:28.000000000 +0200
@@ -162,7 +162,48 @@
     position (pos + 1);
     return this;
   }
-  
+
+  /**
+   * Relative put method. Writes <code>src</code> to the buffer,
+   * starting at the next position.
+   *
+   * @exception BufferOverflowException If there is no remaining
+   * space in this buffer.
+   * @exception ReadOnlyBufferException If this buffer is read-only.
+   */
+  public ByteBuffer put (ByteBuffer src)
+  {
+    if (src instanceof ByteBufferImpl) {
+      put (src.backing_buffer, src.array_offset + src.pos,
+          src.limit - src.pos);
+      src.pos = src.limit;
+      return this;
+    } else {
+      super.put (src);
+      return this;
+    }
+  }
+
+  /**
+   * Relative put method. Writes <code>length</code> bytes from
+   * <code>src</code> to the buffer, starting at <code>offset</code>
+   * in <code>src</code>.
+   *
+   * @exception BufferOverflowException If there is no remaining
+   * space in this buffer.
+   * @exception ReadOnlyBufferException If this buffer is read-only.
+   */
+  public ByteBuffer put (byte[] src, int offset, int length)
+  {
+    checkArraySize(src.length, offset, length);
+    checkIfReadOnly();
+    checkForOverflow(length);
+
+    System.arraycopy (src, offset, backing_buffer, pos + array_offset, length);
+    pos = pos + length;
+    return this;
+  }
+
   /**
    * Absolute get method. Reads the <code>byte</code> at position
    * <code>index</code>.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]