Skip to content

Commit

Permalink
A few performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Nov 18, 2022
1 parent 385bed1 commit 3140097
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.smallrye.config;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
Expand All @@ -17,7 +16,12 @@ public AbstractMappingConfigSourceInterceptor(final Function<String, String> map
}

public AbstractMappingConfigSourceInterceptor(final Map<String, String> mappings) {
this((Serializable & Function<String, String>) name -> mappings.getOrDefault(name, name));
this(new Function<String, String>() {
@Override
public String apply(final String name) {
return mappings.getOrDefault(name, name);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,9 @@ private static Set<String> additionalMappedProperties(final Set<String> mappedPr
// Look for unmatched properties if we can find one in the Env ones and add it
for (String mappedProperty : mappedProperties) {
Set<String> matchedEnvProperties = new HashSet<>();
String endMappedProperty = replaceNonAlphanumericByUnderscores(mappedProperty);
for (String envProperty : envProperties) {
if (envProperty.equalsIgnoreCase(replaceNonAlphanumericByUnderscores(mappedProperty))) {
if (envProperty.equalsIgnoreCase(endMappedProperty)) {
additionalMappedProperties.add(mappedProperty);
matchedEnvProperties.add(envProperty);
break;
Expand Down Expand Up @@ -1144,8 +1145,9 @@ private static void unknownProperties(Set<String> properties, ConfigMappingConte

for (String property : properties) {
boolean found = false;
String envProperty = replaceNonAlphanumericByUnderscores(property);
for (String usedProperty : usedProperties) {
if (usedProperty.equalsIgnoreCase(replaceNonAlphanumericByUnderscores(property))) {
if (usedProperty.equalsIgnoreCase(envProperty)) {
found = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public <K, V> Map<K, V> getValuesAsMap(String name, Converter<K> keyConverter, C
}

/**
*
*
* This method handles calls from both {@link Config#getValue} and {@link Config#getOptionalValue}.<br>
*/
@SuppressWarnings("unchecked")
Expand All @@ -245,17 +245,17 @@ public <T> T getValue(String name, Converter<T> converter) {
/**
* This method handles converting values for both CDI injections and programatical calls.<br>
* <br>
*
*
* Calls for converting non-optional values ({@link Config#getValue} and "Injecting Native Values")
* should throw an {@link Exception} for each of the following:<br>
*
*
* 1. {@link IllegalArgumentException} - if the property cannot be converted by the {@link Converter} to the specified type
* <br>
* 2. {@link NoSuchElementException} - if the property is not defined <br>
* 3. {@link NoSuchElementException} - if the property is defined as an empty string <br>
* 4. {@link NoSuchElementException} - if the {@link Converter} returns {@code null} <br>
* <br>
*
*
* Calls for converting optional values ({@link Config#getOptionalValue} and "Injecting Optional Values")
* should only throw an {@link Exception} for #1 ({@link IllegalArgumentException} when the property cannot be converted to
* the specified type).
Expand Down Expand Up @@ -751,8 +751,9 @@ private static Set<String> generateDottedProperties(final List<ConfigSource> sou
// Collect properties that have the same semantic meaning
Set<String> overrides = new HashSet<>();
for (String property : properties) {
String semanticProperty = replaceNonAlphanumericByUnderscores(property);
for (String envProperty : envProperties) {
if (envProperty.equalsIgnoreCase(replaceNonAlphanumericByUnderscores(property))) {
if (envProperty.equalsIgnoreCase(semanticProperty)) {
overrides.add(envProperty);
break;
}
Expand Down

0 comments on commit 3140097

Please sign in to comment.