Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the profile converter in ProfileConfigSourceInterceptor #1282

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.IntFunction;

import jakarta.annotation.Priority;

import org.eclipse.microprofile.config.spi.Converter;

@Priority(Priorities.LIBRARY + 200)
public class ProfileConfigSourceInterceptor implements ConfigSourceInterceptor {
private static final long serialVersionUID = -6305289277993917313L;

private static final Converter<ArrayList<String>> PROFILES_CONVERTER = newCollectionConverter(
newTrimmingConverter(STRING_CONVERTER), new ArrayListFactory());

private final List<String> profiles;
private final List<String> prefixProfiles;

Expand Down Expand Up @@ -138,7 +144,15 @@ public static String activeName(final String name, final List<String> profiles)
}

public static List<String> convertProfile(final String profile) {
List<String> profiles = newCollectionConverter(newTrimmingConverter(STRING_CONVERTER), ArrayList::new).convert(profile);
List<String> profiles = PROFILES_CONVERTER.convert(profile);
return profiles != null ? profiles : Collections.emptyList();
}

private static class ArrayListFactory implements IntFunction<ArrayList<String>> {

@Override
public ArrayList<String> apply(int value) {
return new ArrayList<String>(value);
}
}
}
Loading