Browse Source

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
pull/25302/head
Marten Deinum 6 years ago committed by Brian Clozel
parent
commit
6316a353bb
  1. 13
      spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

13
spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

@ -247,16 +247,15 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -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();

Loading…
Cancel
Save