summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@hecate.matthew.ath.cx>2008-02-03 11:27:44 +0000
committerMatthew Johnson <mjj29@hecate.matthew.ath.cx>2008-02-03 11:27:44 +0000
commit74a5bd079e5a9c8bd9cb935c106b88c3a44d0184 (patch)
treebb2861cd32708733f48221b6d0eca0945e73eea7 /org
parent0188a56437452117c94bf9f054936e3482162765 (diff)
ensure buffer patch
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/Message.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/org/freedesktop/dbus/Message.java b/org/freedesktop/dbus/Message.java
index 135e0cb..81164cb 100644
--- a/org/freedesktop/dbus/Message.java
+++ b/org/freedesktop/dbus/Message.java
@@ -234,6 +234,21 @@ public class Message
paofs = 0;
}
/**
+ * Ensures there are enough free buffers.
+ * @param num number of free buffers to create.
+ */
+ private void ensureBuffers(int num)
+ {
+ int increase = num - wiredata.length + bufferuse;
+ if (increase > 0) {
+ if (increase < BUFFERINCREMENT) increase = BUFFERINCREMENT;
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Resizing "+bufferuse);
+ byte[][] temp = new byte[wiredata.length+increase][];
+ System.arraycopy(wiredata, 0, temp, 0, wiredata.length);
+ wiredata = temp;
+ }
+ }
+ /**
* Appends a buffer to the buffer list.
*/
protected void appendBytes(byte[] buf)
@@ -608,11 +623,13 @@ public class Message
} else if (data instanceof List) {
Object[] contents = ((List) data).toArray();
int diff = i;
+ ensureBuffers(contents.length*2);
for (Object o: contents)
diff = appendone(sigb, i, o);
i = diff;
} else if (data instanceof Map) {
int diff = i;
+ ensureBuffers(((Map) data).size()*3);
for (Map.Entry<Object,Object> o: ((Map<Object,Object>) data).entrySet())
diff = appendone(sigb, i, o);
if (i == diff) {
@@ -627,6 +644,7 @@ public class Message
i = diff;
} else {
Object[] contents = (Object[]) data;
+ ensureBuffers(contents.length*2);
int diff = i;
for (Object o: contents)
diff = appendone(sigb, i, o);
@@ -643,6 +661,7 @@ public class Message
contents = ((Container) data).getParameters();
else
contents = (Object[]) data;
+ ensureBuffers(contents.length*2);
int j = 0;
for (i++; sigb[i] != ArgumentType.STRUCT2; i++)
i = appendone(sigb, i, contents[j++]);