You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2011/02/17 17:16:59 UTC

svn commit: r1071676 - in /qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport: Binary.java codec/AbstractDecoder.java

Author: robbie
Date: Thu Feb 17 16:16:59 2011
New Revision: 1071676

URL: http://svn.apache.org/viewvc?rev=1071676&view=rev
Log:
QPID-3028: only hold the bytes for the cached string, instead of the entire network read buffer array

Modified:
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java

Modified: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java?rev=1071676&r1=1071675&r2=1071676&view=diff
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java (original)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java Thu Feb 17 16:16:59 2011
@@ -142,4 +142,13 @@ public final class Binary
         return str(ByteBuffer.wrap(bytes, offset, size));
     }
 
+    public boolean hasExcessCapacity()
+    {
+        return size != bytes.length;
+    }
+
+    public Binary copy()
+    {
+        return new Binary(getBytes());
+    }
 }

Modified: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java?rev=1071676&r1=1071675&r2=1071676&view=diff
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java (original)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java Thu Feb 17 16:16:59 2011
@@ -143,10 +143,18 @@ abstract class AbstractDecoder implement
         short size = readUint8();
         Binary bin = get(size);
         String str = str8cache.get(bin);
+
         if (str == null)
         {
             str = decode(bin.array(), bin.offset(), bin.size(), "UTF-8");
-            str8cache.put(bin, str);
+            if(bin.hasExcessCapacity())
+            {
+                str8cache.put(bin.copy(), str);
+            }
+            else
+            {
+                str8cache.put(bin, str);
+            }
         }
         return str;
     }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org