From 7360db817d9b9969eda516b3adf432657906d06c Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 24 Dec 2024 14:43:38 +0100 Subject: [PATCH] Cache the profile converter The convertProfile() method is called several times and there's no need to create the converter again and again. --- .../config/ProfileConfigSourceInterceptor.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java index 6def94f33..fada40e5d 100644 --- a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java +++ b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java @@ -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> PROFILES_CONVERTER = newCollectionConverter( + newTrimmingConverter(STRING_CONVERTER), new ArrayListFactory()); + private final List profiles; private final List prefixProfiles; @@ -138,7 +144,15 @@ public static String activeName(final String name, final List profiles) } public static List convertProfile(final String profile) { - List profiles = newCollectionConverter(newTrimmingConverter(STRING_CONVERTER), ArrayList::new).convert(profile); + List profiles = PROFILES_CONVERTER.convert(profile); return profiles != null ? profiles : Collections.emptyList(); } + + private static class ArrayListFactory implements IntFunction> { + + @Override + public ArrayList apply(int value) { + return new ArrayList(value); + } + } }