use StringBuilder#append(CharSequence, int, int) were possible to improve performance

(similar to LANG-1358, thanks to Stephane Landelle for the suggestion)
This commit is contained in:
pascalschumacher 2017-10-12 19:53:14 +02:00
parent 04ca0852b9
commit 713c77ceda
2 changed files with 6 additions and 7 deletions

View File

@ -387,11 +387,10 @@ public void appendToString(final StringBuffer buffer, final String toString) {
final int pos1 = toString.indexOf(contentStart) + contentStart.length();
final int pos2 = toString.lastIndexOf(contentEnd);
if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
final String data = toString.substring(pos1, pos2);
if (fieldSeparatorAtStart) {
removeLastFieldSeparator(buffer);
}
buffer.append(data);
buffer.append(toString, pos1, pos2);
appendFieldSeparator(buffer);
}
}

View File

@ -308,7 +308,7 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f
if (spaceToWrapAt >= offset) {
// normal case
wrappedLine.append(str.substring(offset, spaceToWrapAt));
wrappedLine.append(str, offset, spaceToWrapAt);
wrappedLine.append(newLineStr);
offset = spaceToWrapAt + 1;
@ -316,7 +316,7 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f
// really long word or URL
if (wrapLongWords) {
// wrap really long word one line at a time
wrappedLine.append(str.substring(offset, wrapLength + offset));
wrappedLine.append(str, offset, wrapLength + offset);
wrappedLine.append(newLineStr);
offset += wrapLength;
} else {
@ -327,11 +327,11 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f
}
if (spaceToWrapAt >= 0) {
wrappedLine.append(str.substring(offset, spaceToWrapAt));
wrappedLine.append(str, offset, spaceToWrapAt);
wrappedLine.append(newLineStr);
offset = spaceToWrapAt + 1;
} else {
wrappedLine.append(str.substring(offset));
wrappedLine.append(str, offset, str.length());
offset = inputLineLength;
}
}
@ -339,7 +339,7 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f
}
// Whatever is left in line is short enough to just pass through
wrappedLine.append(str.substring(offset));
wrappedLine.append(str, offset, str.length());
return wrappedLine.toString();
}