Skip to content

Commit

Permalink
faster RuntimeType.toLowerCase in PropertiesHelper
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and senivam committed Dec 20, 2022
1 parent 3a364bc commit 1633a25
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -221,7 +223,7 @@ public static <T> T getValue(Map<String, ?> 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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 1633a25

Please sign in to comment.