Merge pull request #1622 from dreis2211/SPR-16293

Improve performance of some string operations

Issue: SPR-16293
This commit is contained in:
Juergen Hoeller 2017-12-12 18:36:07 +01:00 committed by GitHub
commit 9d421841d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 17 deletions

View File

@ -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 :

View File

@ -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));
}
}
}

View File

@ -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);

View File

@ -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));
}
}
}

View File

@ -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 {
@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