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
This commit is contained in:
committed by
Oleg Zhurakousky
parent
72ee2fae5d
commit
7450686cfe
@@ -24,6 +24,7 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
@@ -68,6 +69,8 @@ public class AggregateApplicationBuilder implements AggregateApplication,
|
|||||||
private static final Bindable<Map<String, String>> STRING_STRING_MAP = Bindable
|
private static final Bindable<Map<String, String>> STRING_STRING_MAP = Bindable
|
||||||
.mapOf(String.class, String.class);
|
.mapOf(String.class, String.class);
|
||||||
|
|
||||||
|
private static final Pattern DOLLAR_ESCAPE_PATTERN = Pattern.compile("\\$");
|
||||||
|
|
||||||
private SourceConfigurer sourceConfigurer;
|
private SourceConfigurer sourceConfigurer;
|
||||||
|
|
||||||
private SinkConfigurer sinkConfigurer;
|
private SinkConfigurer sinkConfigurer;
|
||||||
@@ -208,7 +211,7 @@ public class AggregateApplicationBuilder implements AggregateApplication,
|
|||||||
// binder
|
// binder
|
||||||
// org.springframework.cloud.stream.aggregation.AggregationTest$TestSource
|
// org.springframework.cloud.stream.aggregation.AggregationTest$TestSource
|
||||||
appConfigurer.namespace = AggregateApplicationUtils.getDefaultNamespace(
|
appConfigurer.namespace = AggregateApplicationUtils.getDefaultNamespace(
|
||||||
appConfigurer.getApp().getName().replaceAll("\\$", "."), i);
|
DOLLAR_ESCAPE_PATTERN.matcher(appConfigurer.getApp().getName()).replaceAll("."), i);
|
||||||
}
|
}
|
||||||
appsToEmbed.put(appToEmbed, appConfigurer.namespace);
|
appsToEmbed.put(appToEmbed, appConfigurer.namespace);
|
||||||
appConfigurers.put(appConfigurer, appConfigurer.namespace);
|
appConfigurers.put(appConfigurer, appConfigurer.namespace);
|
||||||
|
|||||||
Reference in New Issue
Block a user