Reduce String creation in BeanPropertyRowMapper

Prior to this commit the BeanPropertyRowMapper used
String.substring and String.toLowerCase to parse the
field names. This would generate more String than needed.

Instead one could iterate over the internal char[] of the
String and use the Character methods instead. This reduces
the String creation.

Closes gh-25301
This commit is contained in:
Marten Deinum 2020-06-23 08:14:52 +02:00 committed by Brian Clozel
parent 1f78cede72
commit 6316a353bb
1 changed files with 6 additions and 7 deletions

View File

@ -247,16 +247,15 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
if (!StringUtils.hasLength(name)) {
return "";
}
StringBuilder result = new StringBuilder();
result.append(lowerCaseName(name.substring(0, 1)));
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
String slc = lowerCaseName(s);
if (!s.equals(slc)) {
result.append("_").append(slc);
for (int i = 0; i < name.length(); i++) {
char s = name.charAt(i);
if (Character.isUpperCase(s)) {
result.append('_').append(Character.toLowerCase(s));
}
else {
result.append(s);
result.append(Character.toLowerCase(s));
}
}
return result.toString();