mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-10 03:19:01 +00:00
Cache SystemEnvironmentPropertyMapper configuration property names
Add a static cache to `SystemEnvironmentPropertyMapper` for property source name to configuration property name conversion. This update should help ease object allocations for system environment names which are unlikely to change often. Closes gh-14121
This commit is contained in:
+10
-1
@@ -19,9 +19,11 @@ package org.springframework.boot.context.properties.source;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertyName.ToStringFormat;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
|
||||
/**
|
||||
* {@link PropertyMapper} for system environment variables. Names are mapped by removing
|
||||
@@ -39,6 +41,8 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||
|
||||
public static final PropertyMapper INSTANCE = new SystemEnvironmentPropertyMapper();
|
||||
|
||||
private final Map<String, ConfigurationPropertyName> propertySourceNameCache = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
@Override
|
||||
public List<String> map(ConfigurationPropertyName configurationPropertyName) {
|
||||
List<String> mapped = new ArrayList<>(4);
|
||||
@@ -57,7 +61,12 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||
|
||||
@Override
|
||||
public ConfigurationPropertyName map(String propertySourceName) {
|
||||
return convertName(propertySourceName);
|
||||
ConfigurationPropertyName configurationPropertyName = this.propertySourceNameCache.get(propertySourceName);
|
||||
if (configurationPropertyName == null) {
|
||||
configurationPropertyName = convertName(propertySourceName);
|
||||
this.propertySourceNameCache.put(propertySourceName, configurationPropertyName);
|
||||
}
|
||||
return configurationPropertyName;
|
||||
}
|
||||
|
||||
private ConfigurationPropertyName convertName(String propertySourceName) {
|
||||
|
||||
Reference in New Issue
Block a user