Skip to content

Commit 6316a35

Browse files
mdeinumbclozel
authored andcommitted
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
1 parent 1f78ced commit 6316a35

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,15 @@ protected String underscoreName(String name) {
247247
if (!StringUtils.hasLength(name)) {
248248
return "";
249249
}
250+
250251
StringBuilder result = new StringBuilder();
251-
result.append(lowerCaseName(name.substring(0, 1)));
252-
for (int i = 1; i < name.length(); i++) {
253-
String s = name.substring(i, i + 1);
254-
String slc = lowerCaseName(s);
255-
if (!s.equals(slc)) {
256-
result.append("_").append(slc);
252+
for (int i = 0; i < name.length(); i++) {
253+
char s = name.charAt(i);
254+
if (Character.isUpperCase(s)) {
255+
result.append('_').append(Character.toLowerCase(s));
257256
}
258257
else {
259-
result.append(s);
258+
result.append(Character.toLowerCase(s));
260259
}
261260
}
262261
return result.toString();

0 commit comments

Comments
 (0)