Use small buffer in DerBMPString.encode
@@ -148,15 +148,43 @@ void encode(
ASN1OutputStream out)
throws IOException
{
+ int count = string.length;
out.write(BERTags.BMP_STRING);
- out.writeLength(string.length * 2);
+ out.writeLength(count * 2);
- for (int i = 0; i != string.length; i++)
+ byte[] buf = new byte[8];
+
+ int i = 0, limit = count & -4;
+ while (i < limit)
+ {
+ char c0 = string[i], c1 = string[i + 1], c2 = string[i + 2], c3 = string[i + 3];
+ i += 4;
+
+ buf[0] = (byte)(c0 >> 8);
+ buf[1] = (byte)c0;
+ buf[2] = (byte)(c1 >> 8);
+ buf[3] = (byte)c1;
+ buf[4] = (byte)(c2 >> 8);
+ buf[5] = (byte)c2;
+ buf[6] = (byte)(c3 >> 8);
+ buf[7] = (byte)c3;
+
+ out.write(buf, 0, 8);
+ }
+ if (i < count)
+ {
+ int bufPos = 0;
+ do
{
- char c = string[i];
+ char c0 = string[i];
+ i += 1;
+
+ buf[bufPos++] = (byte)(c0 >> 8);
+ buf[bufPos++] = (byte)c0;
+ }
+ while (i < count);
- out.write((byte)(c >> 8));
- out.write((byte)c);
+ out.write(buf, 0, bufPos);
}
}
}
