You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2018/03/22 22:26:06 UTC

qpid-proton-j git commit: PROTON-1808 Grow the buffer by the needed amount when known

Repository: qpid-proton-j
Updated Branches:
  refs/heads/master 88310a5a7 -> 02d6fd818


PROTON-1808 Grow the buffer by the needed amount when known

For the case where we know how much capacity we need we should grow the
buffer directly and not spin trying to get to an amount that
accommodates what we need.

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/02d6fd81
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/02d6fd81
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/02d6fd81

Branch: refs/heads/master
Commit: 02d6fd818b08a11b4383b190a02aca635cde045d
Parents: 88310a5
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Mar 22 18:24:09 2018 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Mar 22 18:24:09 2018 -0400

----------------------------------------------------------------------
 .../org/apache/qpid/proton/engine/impl/FrameWriter.java | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/02d6fd81/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
index fb1b06a..f568b1c 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
@@ -74,8 +74,13 @@ class FrameWriter
 
     private void grow()
     {
+        grow(_bbuf.capacity());  // Double current capacity
+    }
+
+    private void grow(int amount)
+    {
         ByteBuffer old = _bbuf;
-        _bbuf = ByteBuffer.allocate(_bbuf.capacity() * 2);
+        _bbuf = ByteBuffer.allocate(old.capacity() + amount);
         _buffer = new WritableBuffer.ByteBufferWrapper(_bbuf);
         old.flip();
         _bbuf.put(old);
@@ -190,8 +195,9 @@ class FrameWriter
 
         if(payloadSize > 0)
         {
-            while (_buffer.remaining() < payloadSize) {
-                grow();
+            while (_buffer.remaining() < payloadSize)
+            {
+                grow(payloadSize - _buffer.remaining());
             }
 
             int oldLimit = payload.limit();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org