Skip to content

Commit 9d42184

Browse files
authored
Merge pull request #1622 from dreis2211/SPR-16293
Improve performance of some string operations Issue: SPR-16293
2 parents f736b66 + 260ebec commit 9d42184

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ Class<?> getBeanClass() {
341341
PropertyDescriptor getPropertyDescriptor(String name) {
342342
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
343343
if (pd == null && StringUtils.hasLength(name)) {
344-
// Same lenient fallback checking as in PropertyTypeDescriptor...
345-
pd = this.propertyDescriptorCache.get(name.substring(0, 1).toLowerCase() + name.substring(1));
344+
// Same lenient fallback checking as in Property...
345+
pd = this.propertyDescriptorCache.get(StringUtils.uncapitalize(name));
346346
if (pd == null) {
347-
pd = this.propertyDescriptorCache.get(name.substring(0, 1).toUpperCase() + name.substring(1));
347+
pd = this.propertyDescriptorCache.get(StringUtils.capitalize(name));
348348
}
349349
}
350350
return (pd == null || pd instanceof GenericTypeAwarePropertyDescriptor ? pd :

spring-core/src/main/java/org/springframework/core/convert/Property.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,9 @@ private Field getField() {
239239
field = ReflectionUtils.findField(declaringClass, name);
240240
if (field == null) {
241241
// Same lenient fallback checking as in CachedIntrospectionResults...
242-
field = ReflectionUtils.findField(declaringClass,
243-
name.substring(0, 1).toLowerCase() + name.substring(1));
242+
field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name));
244243
if (field == null) {
245-
field = ReflectionUtils.findField(declaringClass,
246-
name.substring(0, 1).toUpperCase() + name.substring(1));
244+
field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name));
247245
}
248246
}
249247
}

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ protected void addClassPathManifestEntries(Set<Resource> result) {
427427
int prefixIndex = filePath.indexOf(':');
428428
if (prefixIndex == 1) {
429429
// Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection
430-
filePath = filePath.substring(0, 1).toUpperCase() + filePath.substring(1);
430+
filePath = StringUtils.capitalize(filePath);
431431
}
432432
UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX +
433433
ResourceUtils.FILE_URL_PREFIX + filePath + ResourceUtils.JAR_URL_SEPARATOR);

spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,24 +469,24 @@ public static String convertUnderscoreNameToPropertyName(@Nullable String name)
469469
StringBuilder result = new StringBuilder();
470470
boolean nextIsUpper = false;
471471
if (name != null && name.length() > 0) {
472-
if (name.length() > 1 && name.substring(1, 2).equals("_")) {
473-
result.append(name.substring(0, 1).toUpperCase());
472+
if (name.length() > 1 && name.charAt(1) == '_') {
473+
result.append(Character.toUpperCase(name.charAt(0)));
474474
}
475475
else {
476-
result.append(name.substring(0, 1).toLowerCase());
476+
result.append(Character.toLowerCase(name.charAt(0)));
477477
}
478478
for (int i = 1; i < name.length(); i++) {
479-
String s = name.substring(i, i + 1);
480-
if (s.equals("_")) {
479+
char c = name.charAt(i);
480+
if (c == '_') {
481481
nextIsUpper = true;
482482
}
483483
else {
484484
if (nextIsUpper) {
485-
result.append(s.toUpperCase());
485+
result.append(Character.toUpperCase(c));
486486
nextIsUpper = false;
487487
}
488488
else {
489-
result.append(s.toLowerCase());
489+
result.append(Character.toLowerCase(c));
490490
}
491491
}
492492
}

spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.LogFactory;
2323

24+
import org.springframework.util.StringUtils;
2425
import org.springframework.web.multipart.MultipartException;
2526
import org.springframework.web.multipart.MultipartHttpServletRequest;
2627
import org.springframework.web.multipart.MultipartResolver;
@@ -67,11 +68,11 @@ public void setResolveLazily(boolean resolveLazily) {
6768
@Override
6869
public boolean isMultipart(HttpServletRequest request) {
6970
// Same check as in Commons FileUpload...
70-
if (!"post".equals(request.getMethod().toLowerCase())) {
71+
if (!"post".equalsIgnoreCase(request.getMethod())) {
7172
return false;
7273
}
7374
String contentType = request.getContentType();
74-
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
75+
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
7576
}
7677

7778
@Override

0 commit comments

Comments
 (0)