Optimize: truncate parameterString (#5396)

This commit is contained in:
novayoung 2020-08-28 12:46:41 +08:00 committed by GitHub
parent a80a55589e
commit f89ed0c315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -44,8 +44,7 @@ public class PreparedStatementParameterBuilder {
return EMPTY_LIST;
}
String parameterString = getParameterString();
return truncate(parameterString);
return getParameterString();
}
private String getParameterString() {
@ -58,8 +57,13 @@ public class PreparedStatementParameterBuilder {
}
stringBuilder.append(parameter);
first = false;
// cut the string as soon as it reached the length limitation
if (maxLength > 0 && (stringBuilder.length() + EMPTY_LIST.length()) > maxLength) {
return format(stringBuilder).substring(0, maxLength) + "...";
}
}
return String.format("[%s]", stringBuilder.toString());
return format(stringBuilder);
}
private int getMaxIndex() {
@ -67,12 +71,8 @@ public class PreparedStatementParameterBuilder {
return Math.min(maxIdx, parameters.length);
}
private String truncate(String parameterString) {
if (maxLength > 0 && parameterString.length() > maxLength) {
parameterString = parameterString.substring(0, maxLength) + "...";
}
return parameterString;
private String format(StringBuilder stringBuilder) {
return String.format("[%s]", stringBuilder.toString());
}
}