summaryrefslogtreecommitdiff
path: root/java/common/src
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2011-02-17 16:16:59 +0000
committerRobert Gemmell <robbie@apache.org>2011-02-17 16:16:59 +0000
commit69f77d093b89b6d606f88830696f302c6015c270 (patch)
tree551ec33ad1643dba5a72f0ebcdce08b49a1411cc /java/common/src
parentfc1e4c575acf0a9a6aba67b5e37bfc132ae386be (diff)
downloadqpid-python-69f77d093b89b6d606f88830696f302c6015c270.tar.gz
QPID-3028: only hold the bytes for the cached string, instead of the entire network read buffer array
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1071676 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/src')
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/Binary.java9
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java10
2 files changed, 18 insertions, 1 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/transport/Binary.java b/java/common/src/main/java/org/apache/qpid/transport/Binary.java
index 4e97855a6f..491a7ac218 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/Binary.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/Binary.java
@@ -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());
+ }
}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java b/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
index a8a4997ae7..09ce6a7eb1 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
@@ -143,10 +143,18 @@ abstract class AbstractDecoder implements Decoder
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;
}