From 7450686cfedaa08efa5f8aeac109a00a3f4aaf41 Mon Sep 17 00:00:00 2001 From: durigon Date: Wed, 19 Sep 2018 18:55:17 +0900 Subject: [PATCH] Refactor String#replaceAll If we repeatedly call String#replaceAll, we internally repeatedly call the regular expression pattern compilation every time as following: ```java public String replaceAll(String regex, String replacement) { return Pattern.compile(regex).matcher(this).replaceAll(replacement); } ``` The modifications are to keep the compiled pattern. Therefore, compiling a relatively expensive regular expression pattern does not have to be done every time. Resolves #1486 --- .../cloud/stream/aggregate/AggregateApplicationBuilder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java index 2ba290746..dfcd499d0 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java @@ -24,6 +24,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; @@ -68,6 +69,8 @@ public class AggregateApplicationBuilder implements AggregateApplication, private static final Bindable> STRING_STRING_MAP = Bindable .mapOf(String.class, String.class); + private static final Pattern DOLLAR_ESCAPE_PATTERN = Pattern.compile("\\$"); + private SourceConfigurer sourceConfigurer; private SinkConfigurer sinkConfigurer; @@ -208,7 +211,7 @@ public class AggregateApplicationBuilder implements AggregateApplication, // binder // org.springframework.cloud.stream.aggregation.AggregationTest$TestSource appConfigurer.namespace = AggregateApplicationUtils.getDefaultNamespace( - appConfigurer.getApp().getName().replaceAll("\\$", "."), i); + DOLLAR_ESCAPE_PATTERN.matcher(appConfigurer.getApp().getName()).replaceAll("."), i); } appsToEmbed.put(appToEmbed, appConfigurer.namespace); appConfigurers.put(appConfigurer, appConfigurer.namespace);