From 1b8176d680a41e75e12104e1ced5ac1cc1df7452 Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 8 Dec 2022 16:23:49 +0100 Subject: [PATCH] faster RuntimeType.toLowerCase in PropertiesHelper Signed-off-by: jansupol --- .../internal/util/PropertiesHelper.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/util/PropertiesHelper.java b/core-common/src/main/java/org/glassfish/jersey/internal/util/PropertiesHelper.java index a351ddccf0..cb1c87b864 100644 --- a/core-common/src/main/java/org/glassfish/jersey/internal/util/PropertiesHelper.java +++ b/core-common/src/main/java/org/glassfish/jersey/internal/util/PropertiesHelper.java @@ -42,6 +42,8 @@ public final class PropertiesHelper { private static final Logger LOGGER = Logger.getLogger(PropertiesHelper.class.getName()); private static final boolean METAINF_SERVICES_LOOKUP_DISABLE_DEFAULT = false; private static final boolean JAXRS_SERVICE_LOADING_ENABLE_DEFAULT = true; + private static final String RUNTIME_SERVER_LOWER = RuntimeType.SERVER.name().toLowerCase(Locale.ROOT); + private static final String RUNTIME_CLIENT_LOWER = RuntimeType.CLIENT.name().toLowerCase(Locale.ROOT); /** * Get system properties. @@ -221,7 +223,7 @@ public static T getValue(Map properties, RuntimeType runtimeType, String runtimeAwareKey = getPropertyNameForRuntime(key, runtimeType); if (key.equals(runtimeAwareKey)) { // legacy behaviour - runtimeAwareKey = key + "." + runtimeType.name().toLowerCase(Locale.ROOT); + runtimeAwareKey = key + "." + toLowerCase(runtimeType); } value = properties.get(runtimeAwareKey); } @@ -255,11 +257,11 @@ public static String getPropertyNameForRuntime(String key, RuntimeType runtimeTy if (runtimeType != null && key.startsWith("jersey.config")) { RuntimeType[] types = RuntimeType.values(); for (RuntimeType type : types) { - if (key.startsWith("jersey.config." + type.name().toLowerCase(Locale.ROOT))) { + if (key.startsWith("jersey.config." + toLowerCase(type))) { return key; } } - return key.replace("jersey.config", "jersey.config." + runtimeType.name().toLowerCase(Locale.ROOT)); + return key.replace("jersey.config", "jersey.config." + toLowerCase(runtimeType)); } return key; } @@ -387,6 +389,20 @@ public static boolean isProperty(final Object value) { } } + /** + * Faster replacement of {@code RuntimeType#name().toLowerCase(Locale.ROOT)} + * @param runtimeType The runtime type to lower case + * @return the lower-cased variant of the {@link RuntimeType}. + */ + private static String toLowerCase(RuntimeType runtimeType) { + switch (runtimeType) { + case CLIENT: + return RUNTIME_CLIENT_LOWER; + default: + return RUNTIME_SERVER_LOWER; + } + } + /** * Prevent instantiation. */