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

faster RuntimeType.toLowerCase in PropertiesHelper #5212

Merged
merged 1 commit into from
Dec 20, 2022
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 @@ -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