db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Pendleton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter
Date Mon, 16 Jul 2007 14:33:04 GMT

    [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12512954

Bryan Pendleton commented on DERBY-2936:

I noticed the patch has changes such as this:

 		ensureLength (1);
-		bytes[offset++] = (byte) (value & 0xff);
+		buffer.put((byte) value);
@@ -485,9 +496,7 @@
 	protected void writeNetworkShort (int value)
 		ensureLength (2);
-		bytes[offset] = (byte) ((value >>> 8) & 0xff);
-		bytes[offset + 1] = (byte) (value & 0xff);
-		offset += 2;
+		buffer.putShort((short) value);

The new code is certainly simpler and clearer, which is great!

But why is it that we no longer need to do the masking and shifting?

Is this something that the ByteBuffer methods do for us automatically?

> Use java.nio.ByteBuffer for buffering in DDMWriter
> --------------------------------------------------
>                 Key: DERBY-2936
>                 URL: https://issues.apache.org/jira/browse/DERBY-2936
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Server
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: d2936-1.diff
> org.apache.derby.impl.drda.DDMWriter uses a byte array as a buffer. Wrapping the array
in a java.nio.ByteBuffer has some advantages, for instance:
>   - utility methods for encoding primitive types into the byte array could be used instead
of manually encoding the values
>   - it allows us to encode strings directly into the buffer (using a CharsetEncoder)
without doing an expensive String.getBytes(String encoding) in an intermediate step
> By using a utility class, the code becomes easier to maintain. Also, ByteBuffer allows
us to access the backing byte array without going through the ByteBuffer interface, so we
still have the possibility to modify the byte array directly in cases where that's more convenient.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message