summaryrefslogtreecommitdiff
path: root/qpid/java
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
commit11b97d4ad43c28a7f94e0b0d918b926bea2fd230 (patch)
tree222f1a39b5b8a066eac58b4f91dc70c508c90f81 /qpid/java
parent712a1e003772d36e4c48d88447c1e3ae517bdda8 (diff)
downloadqpid-python-11b97d4ad43c28a7f94e0b0d918b926bea2fd230.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@1071676 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java9
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java10
2 files changed, 18 insertions, 1 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java
index 4e97855a6f..491a7ac218 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Binary.java
+++ b/qpid/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/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
index a8a4997ae7..09ce6a7eb1 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/codec/AbstractDecoder.java
+++ b/qpid/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;
}