Skip to content
Permalink
Browse files
MIME4J-305 ContentUtil::decode can avoid using StringBuilder (#51)
StringBuilder is an expensive construct, we spend most of our time, for each character, ensuring the capacity of the string builder.

Size being known, the operation simple, we can directly operate on top of a char array.

Gains: 78%
  • Loading branch information
chibenwa committed Sep 4, 2021
1 parent ac4c468 commit a756b7251e03559c7d6b21293fc607f948c52cce
Showing 1 changed file with 3 additions and 3 deletions.
@@ -176,11 +176,11 @@ public static String decode(ByteSequence byteSequence, int offset, int length) {
if (byteSequence == null) {
return null;
}
StringBuilder buf = new StringBuilder(length);
char[] underlying = new char[length];
for (int i = offset; i < offset + length; i++) {
buf.append((char) (byteSequence.byteAt(i) & 0xff));
underlying[i - offset] = (char) (byteSequence.byteAt(i) & 0xff);
}
return buf.toString();
return new String(underlying);
}

/**

0 comments on commit a756b72

Please sign in to comment.