Skip to content
Permalink
Browse files
MIME4J-306 MimeUtil::unfold should group char appends (#52)
Calling repeatedly append requires ensuring the capacity amongst other.

Appends to the string builder can be done for all previous chars when a line delimiter is encountered, thus reducing the cost of the operation.

Gain: 66%
  • Loading branch information
chibenwa committed Sep 4, 2021
1 parent a756b72 commit 0b43a1eef820ae9148013380f3207e6cce23323f
Showing 1 changed file with 9 additions and 2 deletions.
@@ -263,12 +263,19 @@ private static String unfold0(String s, int crlfIdx) {
sb.append(s, 0, crlfIdx);
}

int lastLineBreak = crlfIdx;
for (int idx = crlfIdx + 1; idx < length; idx++) {
char c = s.charAt(idx);
if (c != '\r' && c != '\n') {
sb.append(c);
if (c == '\r' || c == '\n') {
if (idx > lastLineBreak + 1) {
sb.append(s, lastLineBreak + 1, idx);
}
lastLineBreak = idx;
}
}
if (lastLineBreak < s.length() - 1 && s.length() > 0) {
sb.append(s, lastLineBreak + 1, s.length());
}

return sb.toString();
}

0 comments on commit 0b43a1e

Please sign in to comment.