Skip to content

Commit

Permalink
#3, reduce ByteBuffer allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaaaaaron committed May 14, 2019
1 parent cb5ebae commit 26e7a55
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public synchronized void setInput(byte[] buffer, int off, int len) {
SnappyUtil.validateBuffer(buffer, off, len);

if (inputBuffer.capacity() - inputBuffer.position() < len) {
ByteBuffer newBuffer = ByteBuffer.allocateDirect(inputBuffer.position() + len);
int maxSize = Math.max(inputBuffer.position() * 2 , inputBuffer.position() + len);
ByteBuffer newBuffer = ByteBuffer.allocateDirect(maxSize);
inputBuffer.rewind();
newBuffer.put(inputBuffer);
ByteBuffer oldBuffer = inputBuffer;
Expand Down

0 comments on commit 26e7a55

Please sign in to comment.