summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Davidson <jpd@google.com>2015-05-11 22:51:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-05-11 22:51:48 +0000
commit210d15c8e6092c0442f19b08e7c564bffdd7ae12 (patch)
tree35ce8a2f6a759168818efe5d1c07afd0c4bbc342
parent6a6ad15bc94ef60e647fc8752419976d4d33f848 (diff)
parentb6872c8af4117d0e78967e8cced7214a8ac34e2d (diff)
downloadexternal_protobuf-210d15c8e6092c0442f19b08e7c564bffdd7ae12.zip
external_protobuf-210d15c8e6092c0442f19b08e7c564bffdd7ae12.tar.gz
external_protobuf-210d15c8e6092c0442f19b08e7c564bffdd7ae12.tar.bz2
Merge "Speed up little endian int/long writes."
-rw-r--r--java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
index 53060da..4d0b48e 100644
--- a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
@@ -33,6 +33,7 @@ package com.google.protobuf.nano;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
/**
@@ -61,6 +62,7 @@ public final class CodedOutputByteBufferNano {
private CodedOutputByteBufferNano(final ByteBuffer buffer) {
this.buffer = buffer;
+ this.buffer.order(ByteOrder.LITTLE_ENDIAN);
}
/**
@@ -1037,24 +1039,20 @@ public final class CodedOutputByteBufferNano {
/** Write a little-endian 32-bit integer. */
public void writeRawLittleEndian32(final int value) throws IOException {
- writeRawByte((value ) & 0xFF);
- writeRawByte((value >> 8) & 0xFF);
- writeRawByte((value >> 16) & 0xFF);
- writeRawByte((value >> 24) & 0xFF);
+ if (buffer.remaining() < 4) {
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+ buffer.putInt(value);
}
public static final int LITTLE_ENDIAN_32_SIZE = 4;
/** Write a little-endian 64-bit integer. */
public void writeRawLittleEndian64(final long value) throws IOException {
- writeRawByte((int)(value ) & 0xFF);
- writeRawByte((int)(value >> 8) & 0xFF);
- writeRawByte((int)(value >> 16) & 0xFF);
- writeRawByte((int)(value >> 24) & 0xFF);
- writeRawByte((int)(value >> 32) & 0xFF);
- writeRawByte((int)(value >> 40) & 0xFF);
- writeRawByte((int)(value >> 48) & 0xFF);
- writeRawByte((int)(value >> 56) & 0xFF);
+ if (buffer.remaining() < 8) {
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+ buffer.putLong(value);
}
public static final int LITTLE_ENDIAN_64_SIZE = 8;