aboutsummaryrefslogtreecommitdiffhomepage
path: root/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
diff options
context:
space:
mode:
authorGravatar Jeff Davidson <jpd@google.com>2015-05-08 12:40:47 -0700
committerGravatar Brian Duff <bduff@google.com>2015-05-11 16:14:00 -0700
commit695715ad932bd6cf12ce8bbbae1d43178df60cbe (patch)
tree328bc0a7a559e7be3137fe1e471ee1392e7cb5e8 /javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
parentcd141089a120b6c15687e0653848d24682a07d32 (diff)
Speed up little endian int/long writes.
Bug: 20636336 Change-Id: I303d712967f9885f7c3082d00f961f8ab93a6aed
Diffstat (limited to 'javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java')
-rw-r--r--javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
index b1b0c53a..322ada8e 100644
--- a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
+++ b/javanano/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);
}
/**
@@ -1038,24 +1040,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;