Browse Source

Improve performance of some string operations

Issue: SPR-16293
pull/1622/head
Christoph Dreis 8 years ago
parent
commit
260ebeca3a
  1. 6
      spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
  2. 6
      spring-core/src/main/java/org/springframework/core/convert/Property.java
  3. 2
      spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
  4. 14
      spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java
  5. 5
      spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java

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

@ -341,10 +341,10 @@ public class CachedIntrospectionResults { @@ -341,10 +341,10 @@ public class CachedIntrospectionResults {
PropertyDescriptor getPropertyDescriptor(String name) {
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
if (pd == null && StringUtils.hasLength(name)) {
// Same lenient fallback checking as in PropertyTypeDescriptor...
pd = this.propertyDescriptorCache.get(name.substring(0, 1).toLowerCase() + name.substring(1));
// Same lenient fallback checking as in Property...
pd = this.propertyDescriptorCache.get(StringUtils.uncapitalize(name));
if (pd == null) {
pd = this.propertyDescriptorCache.get(name.substring(0, 1).toUpperCase() + name.substring(1));
pd = this.propertyDescriptorCache.get(StringUtils.capitalize(name));
}
}
return (pd == null || pd instanceof GenericTypeAwarePropertyDescriptor ? pd :

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

@ -239,11 +239,9 @@ public final class Property { @@ -239,11 +239,9 @@ public final class Property {
field = ReflectionUtils.findField(declaringClass, name);
if (field == null) {
// Same lenient fallback checking as in CachedIntrospectionResults...
field = ReflectionUtils.findField(declaringClass,
name.substring(0, 1).toLowerCase() + name.substring(1));
field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name));
if (field == null) {
field = ReflectionUtils.findField(declaringClass,
name.substring(0, 1).toUpperCase() + name.substring(1));
field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name));
}
}
}

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

@ -427,7 +427,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol @@ -427,7 +427,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
int prefixIndex = filePath.indexOf(':');
if (prefixIndex == 1) {
// Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection
filePath = filePath.substring(0, 1).toUpperCase() + filePath.substring(1);
filePath = StringUtils.capitalize(filePath);
}
UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX +
ResourceUtils.FILE_URL_PREFIX + filePath + ResourceUtils.JAR_URL_SEPARATOR);

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

@ -469,24 +469,24 @@ public abstract class JdbcUtils { @@ -469,24 +469,24 @@ public abstract class JdbcUtils {
StringBuilder result = new StringBuilder();
boolean nextIsUpper = false;
if (name != null && name.length() > 0) {
if (name.length() > 1 && name.substring(1, 2).equals("_")) {
result.append(name.substring(0, 1).toUpperCase());
if (name.length() > 1 && name.charAt(1) == '_') {
result.append(Character.toUpperCase(name.charAt(0)));
}
else {
result.append(name.substring(0, 1).toLowerCase());
result.append(Character.toLowerCase(name.charAt(0)));
}
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
if (s.equals("_")) {
char c = name.charAt(i);
if (c == '_') {
nextIsUpper = true;
}
else {
if (nextIsUpper) {
result.append(s.toUpperCase());
result.append(Character.toUpperCase(c));
nextIsUpper = false;
}
else {
result.append(s.toLowerCase());
result.append(Character.toLowerCase(c));
}
}
}

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

@ -21,6 +21,7 @@ import javax.servlet.http.Part; @@ -21,6 +21,7 @@ import javax.servlet.http.Part;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
@ -67,11 +68,11 @@ public class StandardServletMultipartResolver implements MultipartResolver { @@ -67,11 +68,11 @@ public class StandardServletMultipartResolver implements MultipartResolver {
@Override
public boolean isMultipart(HttpServletRequest request) {
// Same check as in Commons FileUpload...
if (!"post".equals(request.getMethod().toLowerCase())) {
if (!"post".equalsIgnoreCase(request.getMethod())) {
return false;
}
String contentType = request.getContentType();
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
}
@Override

Loading…
Cancel
Save