Avoided unnecessary substring creation for field error access with wildcard

Issue: SPR-11374
(cherry picked from commit 5be8301)
This commit is contained in:
Juergen Hoeller
2014-01-31 12:47:08 +01:00
parent 3ffbb24211
commit dd5af764b5
2 changed files with 47 additions and 32 deletions

View File

@@ -193,10 +193,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
public Class<?> getFieldType(String field) {
Object value = getFieldValue(field);
if (value != null) {
return value.getClass();
}
return null;
return (value != null ? value.getClass() : null);
}
/**
@@ -209,12 +206,10 @@ public abstract class AbstractErrors implements Errors, Serializable {
if (field.equals(fieldError.getField())) {
return true;
}
if (field.equals("")) {
return false;
}
// Optimization: use charAt instead of endsWith (SPR-11304)
// Optimization: use charAt and regionMatches instead of endsWith and startsWith (SPR-11304)
int endIndex = field.length() - 1;
return (field.charAt(endIndex) == '*' && fieldError.getField().startsWith(field.substring(0, endIndex)));
return (endIndex >= 0 && field.charAt(endIndex) == '*' &&
(endIndex == 0 || field.regionMatches(0, fieldError.getField(), 0, endIndex)));
}