ObjectOutputStream: optimize String serialization

The serialization protocol specifies a quick method to serialize
a String (because that is so common an operation): TC_STRING +
(short)length + bytes. Let's use that, also to make it easier to test
the upcoming changes to TreeMap harmonizing that Avian's serialization
of said class with OpenJDK's.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-10-30 12:31:52 -05:00
parent bba0d25ba5
commit f3189bc79d

View File

@ -284,6 +284,13 @@ public class ObjectOutputStream extends OutputStream implements DataOutput {
rawByte(TC_NULL); rawByte(TC_NULL);
return; return;
} }
if (o instanceof String) {
byte[] bytes = ((String)o).getBytes("UTF-8");
rawByte(TC_STRING);
rawShort(bytes.length);
write(bytes);
return;
}
rawByte(TC_OBJECT); rawByte(TC_OBJECT);
classDesc(o.getClass()); classDesc(o.getClass());
for (Field field : getFields(o.getClass())) { for (Field field : getFields(o.getClass())) {