From 602a06d565bd3ea8c3ae70c69f51abd303bd09d4 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 4 Nov 2015 23:09:11 -0800 Subject: [PATCH] Improve performance of RelaxedNames Replace String.split() with a regex to save compiling the pattern multiple times. See gh-4252 --- .../java/org/springframework/boot/bind/RelaxedNames.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java index 157b760018..a20cdaa312 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedNames.java @@ -36,6 +36,9 @@ public final class RelaxedNames implements Iterable { 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 values = new LinkedHashSet(); @@ -180,7 +183,7 @@ public final class RelaxedNames implements Iterable { 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));