Skip to content

Commit

Permalink
Reduce String creation in BeanPropertyRowMapper
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdeinum authored and bclozel committed Jun 23, 2020
1 parent 1f78ced commit 6316a35
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -247,16 +247,15 @@ protected String underscoreName(String name) {
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();
Expand Down

0 comments on commit 6316a35

Please sign in to comment.