Improve performance of RelaxedNames

Replace String.split() with a regex to save compiling the pattern
multiple times.

See gh-4252
This commit is contained in:
Phillip Webb 2015-11-04 23:09:11 -08:00
parent 98ff0fff29
commit 602a06d565
1 changed files with 4 additions and 1 deletions

View File

@ -36,6 +36,9 @@ public final class RelaxedNames implements Iterable<String> {
private static final Pattern CAMEL_CASE_PATTERN = Pattern.compile("([^A-Z-])([A-Z])");
private static final Pattern SEPARATED_TO_CAMEL_CASE_PATTERN = Pattern
.compile("[_\\-.]");
private final String name;
private final Set<String> values = new LinkedHashSet<String>();
@ -180,7 +183,7 @@ public final class RelaxedNames implements Iterable<String> {
private static String separatedToCamelCase(String value,
boolean caseInsensitive) {
StringBuilder builder = new StringBuilder();
for (String field : value.split("[_\\-.]")) {
for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) {
field = (caseInsensitive ? field.toLowerCase() : field);
builder.append(
builder.length() == 0 ? field : StringUtils.capitalize(field));